NPE with terrain bullet modification

I’m modifying a Terrain in realtime, while some CharacterControl are walking on it. I’m using jbullet (native bullet instead crashes without exception).

This is the exception:

java.lang.NullPointerException
at com.bulletphysics.collision.dispatch.SimulationIslandManager.buildAndProcessIslands(SimulationIslandManager.java:284)
at com.bulletphysics.dynamics.DiscreteDynamicsWorld.solveConstraints(DiscreteDynamicsWorld.java:641)
at com.bulletphysics.dynamics.DiscreteDynamicsWorld.internalSingleStepSimulation(DiscreteDynamicsWorld.java:385)
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)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:251)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)

After changing the TerrainQuad’s geometry, I update the collisionShape this way:


                initLevelAppState.terrain.removeControl(initLevelAppState.landscape);
                bulletAppState.getPhysicsSpace().remove(initLevelAppState.landscape);
                CollisionShape terrainShape =
                        CollisionShapeFactory.createMeshShape(initLevelAppState.sceneModel);
                initLevelAppState.landscape = new RigidBodyControl(terrainShape, 0);
                initLevelAppState.terrain.addControl(initLevelAppState.landscape);
                bulletAppState.getPhysicsSpace().add(initLevelAppState.landscape);

Any you do this in the renderthread?

1 Like

I don’t think. The above snippet in enclosed with this:


        new Thread(new Runnable() {
            public void run() {
//see prev post
        }}).start();

You can’t do that. Only change physics in physics callbacks like the tutorials do it.

1 Like

Thanks! I’ll check it out! :slight_smile:

Well, after some study, I guess that Johan Maasing intended me to use a PhysicsListener. This thing strangely works… I have no idea why I don’t get an Exception instead.


public class DeformableTerrainControl extends RigidBodyControl implements PhysicsTickListener {

    public DeformableTerrainControl(CollisionShape shape){
        super(shape,0);
    }
    
    @Override
    public void prePhysicsTick(PhysicsSpace space, float tpf) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void physicsTick(PhysicsSpace space, float tpf) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}

Solved! Didn’t realized that bullet changes must be done on the update loop… must reread tutorial every now and then :wink: