Author Topic: null pointer at world 1021  (Read 6136 times)

Offline haijin

  • byte
  • *
  • Posts: 37
    • View Profile
null pointer at world 1021
« on: May 23, 2011, 10:54:51 am »
Hi,

I'm getting a Null pointer in World class, line 1021, but only when I setup the world contents at certain point in the code. Might be about the different threads (i.e. onCreate works, onTouchEvent fails) but there might be something else going on, I still can't find the reason. It might help to know what's happening at that line in class World (I think it's version 1.22, downloaded about a month ago).
Here's the exception...
E/AndroidRuntime(14758): FATAL EXCEPTION: GLThread 8
E/AndroidRuntime(14758): java.lang.NullPointerException
E/AndroidRuntime(14758):        at com.threed.jpct.World.renderScene(World.java:1021)
E/AndroidRuntime(14758):        at com.loxai.run.GameRenderer.onDrawFrame(GameRenderer.java:104)
E/AndroidRuntime(14758):        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)
E/AndroidRuntime(14758):        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)

... so, what's the world like in 1021?

Offline Simdanfeg

  • byte
  • *
  • Posts: 41
    • View Profile
Re: null pointer at world 1021
« Reply #1 on: May 23, 2011, 11:21:56 am »
Null pointer in this line "at com.loxai.run.GameRenderer.onDrawFrame(GameRenderer.java:104)"

Offline haijin

  • byte
  • *
  • Posts: 37
    • View Profile
Re: null pointer at world 1021
« Reply #2 on: May 23, 2011, 11:25:48 am »
that's my code calling world.renderScene, which leads to the null pointer in line 1021 of class World

Offline Simdanfeg

  • byte
  • *
  • Posts: 41
    • View Profile
Re: null pointer at world 1021
« Reply #3 on: May 23, 2011, 11:32:38 am »
Your code may be less
"world = new World()"or "fb=new FrameBuffer(gl,width,height)"

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: null pointer at world 1021
« Reply #4 on: May 23, 2011, 11:41:57 am »

Offline haijin

  • byte
  • *
  • Posts: 37
    • View Profile
Re: null pointer at world 1021
« Reply #5 on: May 23, 2011, 11:49:14 am »
yes, I've seen it's not thread safe, and I'm still not sure it relates to a threads problem. The thing is that I always initialize the world and then execute the onDraw (render when dirty) so it shouldn't be directly related to threads... that's why knowing what that line does might help.
Note that the draw is always performed after world manipulation (ticking loop ends with redraw), so no thread problem here (and I've even synchronized the tick/draw blocks, just in case). And, as I said, starting the ticking/drawing at a different spot does work as usual (that's why I suspected a link to onTouchEvent/other thread).
« Last Edit: May 23, 2011, 11:54:39 am by haijin »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: null pointer at world 1021
« Reply #6 on: May 23, 2011, 11:54:18 am »
Not likely...all of these errors that i've seen so far were related to improper use of threads or synchronization. If, as you say, "onTouchEvent fails", you are most likely fiddling around with objects or the world in that method. The rendering happens in another thread, so doing this is asking for trouble...

Offline haijin

  • byte
  • *
  • Posts: 37
    • View Profile
Re: null pointer at world 1021
« Reply #7 on: May 23, 2011, 11:59:20 am »
the onTouchEvent initializes the world (with its contents) and starts the ticking thread. The ticking thread modifies the world and then requests a redraw. The error happens even if I sync tick and draw. Any chance of learning what's in line 1021?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: null pointer at world 1021
« Reply #8 on: May 23, 2011, 12:20:22 pm »
Not sure about the version you are using, but the version from january accesses the framebuffer there. Any chance that your buffer-parameter is null?

Offline haijin

  • byte
  • *
  • Posts: 37
    • View Profile
Re: null pointer at world 1021
« Reply #9 on: May 23, 2011, 12:36:44 pm »
that was one of my first checks, but I checked again, now adding fb.isInitialized():
Utils.log(fb.toString()+" "+fb.isInitialized());
E/AndroidRuntime(18548): java.lang.NullPointerException
E/AndroidRuntime(18548):        at com.threed.jpct.FrameBuffer.isInitialized(FrameBuffer.java:109)

I am wondering now. I create the renderer onCreate, but I don't start drawing on it until much later (on user selection). In the mean time, the GLView is beneath a regular View (containing the main menu)... could it be something like framebuffer being disposed as part of a MemoryHelper.compact or other gc stuff?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: null pointer at world 1021
« Reply #10 on: May 23, 2011, 12:54:38 pm »
Not sure what's the problem is here..can you create a simple test case to reproduce this?

Offline haijin

  • byte
  • *
  • Posts: 37
    • View Profile
Re: null pointer at world 1021
« Reply #11 on: May 23, 2011, 12:56:23 pm »
found it! again, a silly piece of code that had been there for a long time without causing trouble. I was disposing of the fb at the onDraw if the ticker wasn't ready to start processing, I guess it was some sort of racing condition and/or maybe having an early automatic onDraw call on surface creation...
thanks for the replies, which led to finding the issue, and sorry for wasting your time  :-\
in any case, maybe isInitialized should return a false after the fb has been disposed.