I have a setup in my game where physics are updated in a separate thread with an implementation as follows
Physics Processor (Physics Thread)
public class PhysicsProcessor extends Runnable {
private DynamicsWorld world;
public PhysicsProcessor() {
/* basic dynamics world setup with dvbt broadphase :P */
}
public synchronized getDynamicsWorld() { return world; }
@Override
public void run() {
/* update time */
//update phyics
getDynamicsWorld().stepSimulation(/* delta time */);
}
}
Example Object Creation In Main Thread
myPhysicsProcessor.getDynamicsWorld.addRigidBody(/* some rigid body created here */);
The problem is that when the game runs I occasionally get a null pointer exception in the separate thread on "stepSimulation", which was caused by setAabb in my dbvt broadphase.
Does anyone have any suggestions on what I can do to prevent this exception, or how to work around it?