QuantizedBvhNodes ArrayIndexOutOfBoundsException when creating a custom mesh collision shape

I have a geometry that is using a custom mesh, and I’m trying to add collision to it. Everything works fine unless I try to create a collision shape from the mesh. I get this error:



[java]SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.ArrayIndexOutOfBoundsException: 1

at com.bulletphysics.collision.shapes.QuantizedBvhNodes.setQuantizedAabbMax(QuantizedBvhNodes.java:170)

at com.bulletphysics.collision.shapes.QuantizedBvhNodes.setQuantizedAabbMax(QuantizedBvhNodes.java:143)

at com.bulletphysics.collision.shapes.OptimizedBvh.setInternalNodeAabbMax(OptimizedBvh.java:94)

at com.bulletphysics.collision.shapes.OptimizedBvh.buildTree(OptimizedBvh.java:507)

at com.bulletphysics.collision.shapes.OptimizedBvh.build(OptimizedBvh.java:318)

at com.bulletphysics.collision.shapes.BvhTriangleMeshShape.<init>(BvhTriangleMeshShape.java:80)

at com.bulletphysics.collision.shapes.BvhTriangleMeshShape.<init>(BvhTriangleMeshShape.java:63)

at com.jme3.bullet.collision.shapes.MeshCollisionShape.createShape(MeshCollisionShape.java:122)

at com.jme3.bullet.collision.shapes.MeshCollisionShape.createCollisionMesh(MeshCollisionShape.java:77)

at com.jme3.bullet.collision.shapes.MeshCollisionShape.<init>(MeshCollisionShape.java:65)

[/java]



Then it leads to this line:



[java]MeshCollisionShape shape = new MeshCollisionShape(((Geometry) MyGeom).getMesh());[/java]



I have also tried calling MyGeom.updateModelBound() before and after but the results are the same. The geometry is held in a node, so I used this code from the Hello Collision tutorial:



[java]CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) MyNode);

RigidBodyControl rbc = new RigidBodyControl(sceneShape, 0);

MyNode.addControl(rbc);

bulletAppState.getPhysicsSpace().add(rbc);

[/java]



This gives me a similar stack trace:



[java]SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.ArrayIndexOutOfBoundsException: 1

at com.bulletphysics.collision.shapes.QuantizedBvhNodes.setQuantizedAabbMax(QuantizedBvhNodes.java:170)

at com.bulletphysics.collision.shapes.QuantizedBvhNodes.setQuantizedAabbMax(QuantizedBvhNodes.java:143)

at com.bulletphysics.collision.shapes.OptimizedBvh.setInternalNodeAabbMax(OptimizedBvh.java:94)

at com.bulletphysics.collision.shapes.OptimizedBvh.buildTree(OptimizedBvh.java:507)

at com.bulletphysics.collision.shapes.OptimizedBvh.build(OptimizedBvh.java:318)

at com.bulletphysics.collision.shapes.BvhTriangleMeshShape.<init>(BvhTriangleMeshShape.java:80)

at com.bulletphysics.collision.shapes.BvhTriangleMeshShape.<init>(BvhTriangleMeshShape.java:63)

at com.jme3.bullet.collision.shapes.MeshCollisionShape.createShape(MeshCollisionShape.java:122)

at com.jme3.bullet.collision.shapes.MeshCollisionShape.createCollisionMesh(MeshCollisionShape.java:77)

at com.jme3.bullet.collision.shapes.MeshCollisionShape.<init>(MeshCollisionShape.java:65)

at com.jme3.bullet.util.CollisionShapeFactory.createSingleMeshShape(CollisionShapeFactory.java:194)

at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:95)

at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:117)

at com.jme3.bullet.util.CollisionShapeFactory.createMeshCompoundShape(CollisionShapeFactory.java:126)

at com.jme3.bullet.util.CollisionShapeFactory.createMeshShape(CollisionShapeFactory.java:153)

[/java]



That leads to the line where I make the collision shape again.

From searching I came across two threads that had the same problem, here

http://hub.jmonkeyengine.org/groups/jmonkeyplatform/forum/topic/problem-com-bulletphysics-collision-shapes-does-not-exist/

and here

http://hub.jmonkeyengine.org/groups/physics/forum/topic/arrayindexoutofboundsexception-when-creating-collisionshape/

but both of those seem to end with the solution of updating with the nightly build, which I have tried yesterday and today with no difference. I also tried using a CapsuleCollisionShape, and that worked, but my mesh is part of the floor so it cannot use that shape.

Your mesh does not consist only of triangles, you made a mistake somewhere.

1 Like

Thanks, as it turns out, some of the meshes I was making were empty (no vertices, texCoords or triangles) and that was causing the error when it tried to make a collision shape from them.