null pointer at world 1021

Started by haijin, May 23, 2011, 10:54:51 AM

Previous topic - Next topic

haijin

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?

Simdanfeg

Null pointer in this line "at com.loxai.run.GameRenderer.onDrawFrame(GameRenderer.java:104)"

haijin

that's my code calling world.renderScene, which leads to the null pointer in line 1021 of class World

Simdanfeg

Your code may be less
"world = new World()"or "fb=new FrameBuffer(gl,width,height)"


haijin

#5
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).

EgonOlsen

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...

haijin

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?

EgonOlsen

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?

haijin

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?

EgonOlsen

Not sure what's the problem is here..can you create a simple test case to reproduce this?

haijin

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.