Author Topic: Random Crash in onDrawFrame  (Read 2467 times)

Offline subhalakshmi27

  • byte
  • *
  • Posts: 21
    • View Profile
Random Crash in onDrawFrame
« on: August 03, 2012, 03:46:50 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Random Crash in onDrawFrame
« Reply #1 on: August 03, 2012, 04:00:11 pm »
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.