www.jpct.net
jPCT-AE - a 3d engine for Android => Support => Topic started by: ashunkhs on November 06, 2012, 10:31:41 am
-
Hi
I am trying to load 5-6 md2 model on my GL. But it it taking more time and my app become stuck (Black screen) . So i tried to lode it in background using thread or AsyncTask. But i am getting null pointer error in onDrow() . when i used any model object . otherwise blank screen (without model).
class LoadModelAsyncTask extends AsyncTask<Void, Integer, Boolean>
{
protected Boolean doInBackground(Void... params)
{
System.out.println("i m doInBackground");
ogro=loadModel(Environment.getExternalStorageDirectory() +"/texture_one.jpg",Environment.getExternalStorageDirectory() + "/logo_one.md2",0.25f);
ogroA=loadModel(Environment.getExternalStorageDirectory() +"/texture_one.jpg",Environment.getExternalStorageDirectory() + "/circle_one.md2",0.25f);
return null;
}
protected void onPostExecute(Boolean result)
{
System.out.println("i m onPostExecute");
world.addObject(ogro);
world.addObject(ogroA);
world.buildAllObjects();
}
}
and call it in
onSurfaceChange() {
mLoadModelAsyncTask = new LoadModelAsyncTask();
mLoadModelAsyncTask.execute();
cam.lookAt(ogro.getTransformedCenter()); ........1
cam.lookAt(ogroA.getTransformedCenter());.........2
}
here geting null pointer in line 1 and 2..aswell onDrow().
if any solution pls ..reply soon..!!
8)
-
You are not allowed to fiddle around with the world in anything but the rendering thread or your setup code (jPCT-AE isn't thread safe). If you add objects while the world is being rendered, everything may happen. A simple solution is to load the model in the thread but add it in onDraw after the loading has finished.
-
hi sir
As u told i load a model in thread in serfaceChanged() and add the model into world in onDrow().
public void onDrawFrame(GL10 gl)
{
if(world.getObjects()==null)
{
world.addObject(ogro); ......................1
world.addObject(ogroA);
world.buildAllObjects();
................
.....
but i m getting the null pointer on line ..1. and following lines..
another way to solve it../
-
Please post the exception's stack trace. What you claim that happens actually can't happen for two reasons:
- That line can cause a nullpointer only if world is null. But world can't be null, because you access it before in the if-clause.
- That code never gets executed, because world.getObjects() never returns null.
-
Hi
Now i am not getting any exception but now my model is not visible. it shows blank surface .following is my code.....
public void onSurfaceChanged(GL10 gl, int w, int h) {
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(gl, w, h);
world = new World();
world.setAmbientLight(100, 100, 100);
res = getResources();
sun = new Light(world);
sun.setIntensity(250, 250, 250);
tm = TextureManager.getInstance();
mLoadModelAsyncTask = new LoadModelAsyncTask(); // loading model in thread
mLoadModelAsyncTask.execute();
cam = world.getCamera();
world.getCamera().setPosition(0, 0, -20);
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
//cam.lookAt(ogro.getTransformedCenter());
//cam.lookAt(ogroA.getTransformedCenter());
SimpleVector sv = new SimpleVector();
sv.y -= 50;
sv.z -= 100;
sun.setPosition(sv);
MemoryHelper.compact();
}
public void onDrawFrame(GL10 gl)
{
if(ogro!=null&& ogroA!=null)
{
System.out.println("world--------------->"+world); //world is not null
System.out.println("ogro--------------->"+ogro); // model is not null
world.addObject(ogro);
world.addObject(ogroA);
world.buildAllObjects();
}
but object is not visible on surface ..pls check out the problem....and !!!
-
hi
thanks for help ..its working fine....