Difference between revisions of "Nullpointer during rendering and/or collision detection"

From JPCT
Jump to: navigation, search
(Solution)
(The problem)
 
Line 2: Line 2:
  
 
From time to time, your application exits with a null pointer exception in either the rendering thread or while calling one of the collision detection methods.
 
From time to time, your application exits with a null pointer exception in either the rendering thread or while calling one of the collision detection methods.
 +
Other symptoms might be flickering or object distortions in some frames.
  
 
=Possible reason=
 
=Possible reason=

Latest revision as of 15:16, 16 May 2013

The problem

From time to time, your application exits with a null pointer exception in either the rendering thread or while calling one of the collision detection methods. Other symptoms might be flickering or object distortions in some frames.

Possible reason

jPCT (as well as jPCT-AE) isn't thread safe. That means that at runtime, no other thread is allowed to work on jPCT related object than the rendering thread itself. If you are familiar with the way in which Swing works: It's very similar to that.

If you encounter this problem, the most likely reason is that you are doing work in multiple threads which should be done in the render thread only. This often happens if one works on jPCT related instances in some event listener method.

Solution

Don't do this. Let the event listener method set a flag, evaluate this in the render thread and do the work there.

Another option is to synchronize rendering and event processing, but i don't encourage you to do this. It's error-prone and doesn't have a real advantage.