NullPointerException in Geometry.applyStates()

Created a quad, did NOT set any render states, placed it in the ortho queue.



I got


java.lang.NullPointerException
   at com.jme.scene.Geometry.applyStates(Geometry.java:826)
   at com.jme.scene.Geometry.draw(Geometry.java:842)
   at com.jme.scene.TriMesh.draw(TriMesh.java:265)
   at com.jme.renderer.RenderQueue.renderOrthoBucket(RenderQueue.java:202)
   at com.jme.renderer.RenderQueue.renderBuckets(RenderQueue.java:154)
   at com.jme.renderer.lwjgl.LWJGLRenderer.displayBackBuffer(LWJGLRenderer.java:487)
   at yourobot.core.StateBasedGameEngine.start(StateBasedGameEngine.java:235)
   at yourobot.test.CircuitTest.main(CircuitTest.java:32)



Looking at the code, I'd say that under these circumstances the states array is initialized to all null references. Just a minor bug though. No one is likely adding quads without any render states.

Try calling updateRenderState on the root node.

Yes Badmi, I noticed that this works.



I just thought, even if I don’t do this, it should not throw a NullPointerException.

Good point. I’ll look into it. One arguement is though that it forces you to be aware of the update RS method and the need to call it… But on the other hand, it’s an ugly result.

Update: I’ve removed the possibility of getting an NPE in Geometry.applyStates. if your state is null, it is ignored and currentState is also made null.