NullPointerException in CollisionWorld

I’m having some issues with my physical entities. Sometimes one of them triggers:

java.lang.NullPointerException at com.bulletphysics.collision.dispatch.CollisionWorld$RayResultCallback.needsCollision(CollisionWorld.java:673) at com.bulletphysics.collision.dispatch.CollisionWorld.rayTest(CollisionWorld.java:555) at com.jme3.bullet.PhysicsSpace.rayTest(PhysicsSpace.java:714) at com.jme3.bullet.control.BetterCharacterControl.checkOnGround(BetterCharacterControl.java:468) at eu.cherrytree.zaria.tests.maptest.FixedCharacterControl.checkOnGround(FixedCharacterControl.java:47) at com.jme3.bullet.control.BetterCharacterControl.prePhysicsTick(BetterCharacterControl.java:166) at com.jme3.bullet.PhysicsSpace$3.internalTick(PhysicsSpace.java:259) at com.bulletphysics.dynamics.DiscreteDynamicsWorld.internalSingleStepSimulation(DiscreteDynamicsWorld.java:365) at com.bulletphysics.dynamics.DiscreteDynamicsWorld.stepSimulation(DiscreteDynamicsWorld.java:339) at com.jme3.bullet.PhysicsSpace.update(PhysicsSpace.java:330) at com.jme3.bullet.PhysicsSpace.update(PhysicsSpace.java:317) at com.jme3.bullet.BulletAppState.render(BulletAppState.java:257) at com.jme3.app.state.AppStateManager.render(AppStateManager.java:300)

I can’t really pinpoint the cause, seems random, but surely isn’t.
Does anyone have any suggestions what might be wrong?

My guess is that it has something to do with the betterCharacterControl because it has not official been released and still contains lots of bugs. Also make sure you have all the rays and collision results defined before you use a method.

Thanks for the answer. However I did manage to figure it out.

The BetterCharacterControl is fine. It was my fault. I was adding physical entities to the root node and the physical world not on the render thread. The weird this is that it failed only about 2% of the time.

Not wierd at all, as it would be a classic race condition, if you happened to do that during a “safe” moment you would be fine. Essentially each time you did it the behaviour was entirely random based on the exact state of the threads at that time.

Hello to everyone!

I have exactly the same problem with RaycastVehicle:

at com.bulletphysics.collision.dispatch.CollisionWorld$RayResultCallback.needsCollision(CollisionWorld.java:673) at com.bulletphysics.collision.dispatch.CollisionWorld.rayTest(CollisionWorld.java:555) at com.bulletphysics.dynamics.vehicle.DefaultVehicleRaycaster.castRay(DefaultVehicleRaycaster.java:49) at com.bulletphysics.dynamics.vehicle.RaycastVehicle.rayCast(RaycastVehicle.java:216) at com.bulletphysics.dynamics.vehicle.RaycastVehicle.updateVehicle(RaycastVehicle.java:317) at com.bulletphysics.dynamics.DiscreteDynamicsWorld.updateVehicles(DiscreteDynamicsWorld.java:474) at com.bulletphysics.dynamics.DiscreteDynamicsWorld.internalSingleStepSimulation(DiscreteDynamicsWorld.java:396) at com.bulletphysics.dynamics.DiscreteDynamicsWorld.stepSimulation(DiscreteDynamicsWorld.java:339) at com.jme3.bullet.PhysicsSpace.update(PhysicsSpace.java:324) at com.jme3.bullet.PhysicsSpace.update(PhysicsSpace.java:311) at com.jme3.bullet.BulletAppState.render(BulletAppState.java:185) at com.jme3.app.state.AppStateManager.render(AppStateManager.java:268) at com.jme3.app.SimpleApplication.update(SimpleApplication.java:250) at com.jme3.system.NullContext.run(NullContext.java:131) at java.lang.Thread.run(Thread.java:722)

But unfortunately i don’t understand how to solve it… This error appears on headless server, which have own BulletAppState. But server doesn’t draw anything…
I miss something? Can someone explain me what cause this exception and how to fix it?

Upd:. Hm, i just moved code, where i am adding node to rootNode , into render thread, and now it works fine…