Odd Behaviour of Bridge with RigidBody

I’m currently working on building a scene for a game I’ve been making. In this scene, there is a bridge (currently, it looks terrible, but that will be changed later, after it is working). In this game additionally, every object has it’s own rigidbody so that the player can push and move things around and so that they can interact with various weapons to be added in the future. I may eventually have them in several BatchNodes as well. I created a long and skinny object in Blender to represent planks, then I assembled them into a .j3o of a bridge in the SDK (using “Create Scene” on the context menu to create the obejct in the models folder). The bridge .j3o is linked to the plank.j3o, and the main scene’s .j3o is linked to the bridge’s .j3o. I have written some code to go through all objects in the scene and add RigidBodies as needed (based on the name of the objects\nodes). When I attempt to run the game, the bridge stays a fixed position from the player as it falls from the sky (there is no proper spawn point yet) until it goes through the terrain and becomes invisible since it is underneath the terrain and out of view of the player. Then, a few seconds later, the game crashes with the stack trace below. Thanks in advance for any possible answers!

RigidBody code:

private void applyPhysics(Spatial spatial){
        boolean doChildren = true;
        
        if(spatial.getName().startsWith("brick") || spatial.getName().startsWith("cube")){
            RigidBodyControl rb = new RigidBodyControl(CollisionShapeFactory.createBoxShape(spatial), 1f);
            spatial.addControl(rb);
            bullet.getPhysicsSpace().add(rb);
            doChildren = false;
        }else if(spatial.getName().equals("plank")){
            RigidBodyControl rb = new RigidBodyControl(CollisionShapeFactory.createMeshShape(spatial), 100f);
            spatial.addControl(rb);
            bullet.getPhysicsSpace().add(rb);
            doChildren = false;
        }else if(spatial.getName().equals("terrain-mainScene")){
            RigidBodyControl rb = new RigidBodyControl(CollisionShapeFactory.createMeshShape(spatial), 0f);
            spatial.addControl(rb);
            bullet.getPhysicsSpace().add(rb);
            doChildren = false;
        }
        
        if(doChildren && spatial instanceof Node){
            Node node = ((Node) spatial);
            for(Spatial currentSpatial : node.getChildren()){
                applyPhysics(currentSpatial);
            }
        }
    }

Sceenshot of the bridge in the SDK editor:
The bridge is slightly above the terrain with the intent that once the game starts it falls into a reasonable position.

Stack trace:

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
    at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:119)
    at com.bulletphysics.collision.dispatch.CompoundCollisionAlgorithm.destroy(CompoundCollisionAlgorithm.java:76)
    at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:120)
    at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.cleanOverlappingPair(HashedOverlappingPairCache.java:219)
    at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.removeOverlappingPair(HashedOverlappingPairCache.java:91)
    at com.bulletphysics.collision.broadphase.DbvtBroadphase.collide(DbvtBroadphase.java:145)
    at com.bulletphysics.collision.broadphase.DbvtBroadphase.calculateOverlappingPairs(DbvtBroadphase.java:235)
    at com.bulletphysics.collision.dispatch.CollisionWorld.performDiscreteCollisionDetection(CollisionWorld.java:139)
    at com.bulletphysics.dynamics.DiscreteDynamicsWorld.internalSingleStepSimulation(DiscreteDynamicsWorld.java:378)
    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:745)


Exception: java.lang.NullPointerException thrown from the UncaughtExceptionHandler in thread "LWJGL Renderer Thread"

A mesh shape may have no mass (it has to be static).

How should I create a bridge then? I was originally using a box collier – I only changed it to a mesh for debugging since the same issue happens with a box collier.

I guess you might be adding (or removing) the physics objects multiple times to the physics space or something. I hope you’re also aware that generally adding a physics object for every plank is the naive approach and won’t get you any real game. Check the best practices docs on that.

I checked the best practices document (assuming you mean this), I didn’t see anything about RIgidBodies or even physics at all. Perhaps you could link to where what you described is or just explain it here?

http://wiki.jmonkeyengine.org/doku.php/jme3:beginner:hello_physics