Random Crash in onDrawFrame

Started by subhalakshmi27, August 03, 2012, 03:46:50 PM

Previous topic - Next topic

subhalakshmi27

Hi All,

In my application based on gesture event Objects are moved. On collision with other object, I remove the object. Some times I am getting random crashes onDrawFrame() because of NullPointerException in drawVertexArray.


08-03 19:05:13.160: E/AndroidRuntime(18542): FATAL EXCEPTION: GLThread 18
08-03 19:05:13.160: E/AndroidRuntime(18542): java.lang.NullPointerException
08-03 19:05:13.160: E/AndroidRuntime(18542):    at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2127)
08-03 19:05:13.160: E/AndroidRuntime(18542):    at com.threed.jpct.World.draw(World.java:1354)
08-03 19:05:13.160: E/AndroidRuntime(18542):    at com.threed.jpct.World.draw(World.java:1135)
08-03 19:05:13.160: E/AndroidRuntime(18542):    at com.goora.matthew.nappybunch.ui.BlendRenderer.onDrawFrame(BlendRenderer.java:445)
08-03 19:05:13.160: E/AndroidRuntime(18542):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1388)
08-03 19:05:13.160: E/AndroidRuntime(18542):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1138)

I am not sure what I am doing wrong. Any idea why this can happen?

EgonOlsen

What do you expect? You are removing objects from the world in parallel to the rendering thread. jPCT-AE isn't thread safe. You may not remove or add objects in another thread than the rendering thread (or at setup time, but that's another story).
I suggest to let the gesture event method just set some flags and do all the logic in onDrawFrame() instead. Collision detection itself might be able to run in parallel to the rendering, so that it may be sufficient to just do the object removal in the rendering thread, but i wouldn't rely on this.