Hello,
when I’m using jbullet, I have some random errors are appearing (even when a player is just walking). I have tried using different libraries from maven, such as:
cz.advel.jbullet : jbullet
com.github.stephengold : jbullet
com.github.stephengold : Libbulletjme
Now I’m using last, and I receive randomly these errors that can sometimes crash my program, or stop world generation thread:
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:781)
at com.jme3.bullet.control.BetterCharacterControl.checkOnGround(BetterCharacterControl.java:503)
at com.jme3.bullet.control.BetterCharacterControl.prePhysicsTick(BetterCharacterControl.java:199)
at com.jme3.bullet.PhysicsSpace$3.internalTick(PhysicsSpace.java:318)
...
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
at com.jme3.bullet.BulletAppState.postRender(BulletAppState.java:386)
at com.jme3.app.state.AppStateManager.postRender(AppStateManager.java:381)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:274)
...
Exception in thread "Chunk" java.lang.NullPointerException
at com.jme3.bullet.PhysicsSpace.addRigidBody(PhysicsSpace.java:617)
at com.jme3.bullet.PhysicsSpace.addCollisionObject(PhysicsSpace.java:457)
at com.jme3.bullet.control.RigidBodyControl.setPhysicsSpace(RigidBodyControl.java:394)
at com.jme3.bullet.PhysicsSpace.add(PhysicsSpace.java:436)
...
Exception in thread "pool-8-thread-1" java.lang.ClassCastException: class com.bulletphysics.collision.shapes.CompoundShape cannot be cast to class com.bulletphysics.collision.shapes.ConvexShape (com.bulletphysics.collision.shapes.CompoundShape and com.bulletphysics.collision.shapes.ConvexShape are in unnamed module of loader 'app')
at com.bulletphysics.collision.dispatch.ConvexConvexAlgorithm.processCollision(ConvexConvexAlgorithm.java:109)
at com.bulletphysics.collision.dispatch.ConvexTriangleCallback.processTriangle(ConvexTriangleCallback.java:163)
at com.bulletphysics.collision.shapes.BvhTriangleMeshShape$MyNodeOverlapCallback.processNode(BvhTriangleMeshShape.java:268)
at com.bulletphysics.collision.shapes.OptimizedBvh.walkStacklessQuantizedTree(OptimizedBvh.java:955)
at com.bulletphysics.collision.shapes.OptimizedBvh.reportAabbOverlappingNodex(OptimizedBvh.java:703)
at com.bulletphysics.collision.shapes.BvhTriangleMeshShape.processAllTriangles(BvhTriangleMeshShape.java:163)
at com.bulletphysics.collision.shapes.TriangleMeshShape.localGetSupportingVertex(TriangleMeshShape.java:71)
at com.bulletphysics.collision.shapes.TriangleMeshShape.recalcLocalAabb(TriangleMeshShape.java:88)
at com.bulletphysics.collision.shapes.BvhTriangleMeshShape.<init>(BvhTriangleMeshShape.java:84)
at com.bulletphysics.collision.shapes.BvhTriangleMeshShape.<init>(BvhTriangleMeshShape.java:63)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.createShape(MeshCollisionShape.java:138)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.createCollisionMesh(MeshCollisionShape.java:89)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.<init>(MeshCollisionShape.java:77)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.<init>(MeshCollisionShape.java:67)
at com.jme3.bullet.util.CollisionShapeFactory.createSingleMeshShape(CollisionShapeFactory.java:257)
at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:123)
at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:143)
at com.jme3.bullet.util.CollisionShapeFactory.createMeshCompoundShape(CollisionShapeFactory.java:158)
at com.jme3.bullet.util.CollisionShapeFactory.createMeshShape(CollisionShapeFactory.java:200)
...
Also, I’m using BulletAppState.ThreadingType.PARALLEL
, and not BulletAppState.ThreadingType.SEQUENTIAL
because then I receive even more errors.
The BetterCharacterControl has nothing any special:
playerNode.setLocalTranslation(new Vector3f(4, 5, 2));
player = new BetterCharacterControl(0.5f, 6f, 2f);
player.setJumpForce(new Vector3f(0f, 35f, 0f));
playerNode.addControl(player);
bulletAppState.getPhysicsSpace().add(player);
bulletAppState.getPhysicsSpace().addAll(playerNode);
rootNode.attachChild(playerNode);
And for moving player: player.setWalkDirection(walkDirection.multLocal(1))
Finally, for adding physics for terrain(chunks) I use:
CollisionShape shape = CollisionShapeFactory.createMeshShape(chunkSpat)
RigidBodyControl chunkPhys = new RigidBodyControl(shape, 0);
PhysicsSpace state = Storage.bulletAppState.getPhysicsSpace();
chunkSpat.addControl(chunkPhys);
Transformation.spawnObject(chunkSpat, node, app);
state.add(chunkPhys);
I really don’t know what to do.