Author Topic: TransformVertices crash  (Read 1688 times)

Offline Immortal Carp

  • byte
  • *
  • Posts: 2
    • View Profile
TransformVertices crash
« on: November 02, 2014, 03:43:31 pm »
Hi. Sorry for my english but i think you will understand  ;)

i'm working on augmented reality application, where i have four instances of Object3D and they are added/removed from world according to state of image fom camera. Problem is that the application sometimes crashes on onDrawFrame() method and I can't  find out why.

There is a log(it is allways the same)
FATAL EXCEPTION: GLThread 42496
 java.lang.RuntimeException: [ 1414843865465 ] - ERROR: java.lang.NullPointerException
    at com.threed.jpct.Object3D.transformVertices(Object3D.java:5879)
    at com.threed.jpct.World.renderScene(World.java:1070)
    at com.example.app.views.AppRenderer.onDrawFrame(AppRenderer.java:84)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
    at com.threed.jpct.Logger.log(Logger.java:193)
    at com.threed.jpct.Logger.log(Logger.java:150)
    at com.threed.jpct.World.renderScene(World.java:1085)
    at com.example.app.views.AppRenderer.onDrawFrame(AppRenderer.java:84)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)


and there is code of onDrawFrame() method:
Code: [Select]
@Override
public void onDrawFrame(GL10 gl) {
while (!CameraModel.getInstance().mBackgroundLoaded) {
Thread.yield();
}
fb.clear(back);
CameraModel model = CameraModel.getInstance();
mBackgroundTex.overrideTexelData(model.getBackground());
fb.blit(mBackgroundTex, 0, 0, 0, 0, (int) model.mPow2width,
(int) model.mPow2Height, model.mCamWidth, model.mCamHeight, -1,
false);
world.renderScene(fb); //app crashes on this line
world.draw(fb);
fb.display();
if (mSaveScene) {
int[] array = fb.getPixels();
IntBuffer dst = IntBuffer.wrap(array);
dst.rewind();
Bitmap bmp = Bitmap.createBitmap(fb.getWidth(), fb.getHeight(),
Bitmap.Config.ARGB_8888);
bmp.copyPixelsFromBuffer(dst);
saveScene(bmp);
mSaveScene = false;
}
}
Adding and removing object:
Code: [Select]
public void addObject(Object3D obj) {
world.addObject(obj);
}

public void removeObject(Object3D obj) {
world.removeObject(obj);
}
this happening in openGL thread

Have you any ideas what I'm doing wrong ?
Thanks

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: TransformVertices crash
« Reply #1 on: November 02, 2014, 03:48:57 pm »
The reason in 99.9% of these cases is that rendering and adding/removing of objects don't happen in the same thread. In your case, you state that add and remove happen in openGL thread, but i'm not sure what you mean by that. They clearly don't happen in onDrawFrame, which is the place in which they should happen. Either that, or synchronize them with onDrawFrame.

Offline Immortal Carp

  • byte
  • *
  • Posts: 2
    • View Profile
Re: TransformVertices crash
« Reply #2 on: November 02, 2014, 04:08:55 pm »
Yes sorry I forgot.  Previously in onDrawFrame was happening all image analysis but I changed it and there is small chance that the analysis will be shorter than drawing.
Thank you. 

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: TransformVertices crash
« Reply #3 on: November 02, 2014, 04:30:59 pm »
No problem. Just never rely on timing when synchronizing multiple threads, because even if it doesn't happen today, the next os version, runtime or device will break your app.