IndexOutOfBoundsException at Buffer.checkIndex with MeshCollisionShape

I get the following exception when creating a RigidBodyControl(0.0f):

java.lang.IndexOutOfBoundsException
at java.nio.Buffer.checkIndex(Buffer.java:538)
at java.nio.HeapByteBuffer.getFloat(HeapByteBuffer.java:461)
at com.bulletphysics.collision.shapes.ByteBufferVertexData.getVertex(ByteBufferVertexData.java:58)
at com.bulletphysics.collision.shapes.VertexData.getTriangle(VertexData.java:53)
at com.bulletphysics.collision.shapes.StridingMeshInterface.internalProcessAllTriangles(StridingMeshInterface.java:51)
at com.bulletphysics.collision.shapes.StridingMeshInterface.calculateAabbBruteForce(StridingMeshInterface.java:78)
at com.bulletphysics.collision.shapes.BvhTriangleMeshShape.<init>(BvhTriangleMeshShape.java:76)
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:214)
at com.jme3.bullet.util.CollisionShapeFactory.createMeshShape(CollisionShapeFactory.java:171)
at com.jme3.bullet.control.RigidBodyControl.createCollisionShape(RigidBodyControl.java:125)
at com.jme3.bullet.control.RigidBodyControl.setSpatial(RigidBodyControl.java:100)
at com.jme3.scene.Spatial.addControl(Spatial.java:591)

The only topics I could find were solved by not adding empty meshes, but that is not the case:

Mesh resisted physicsation by java.lang.IndexOutOfBoundsException (vertices: 2304; normals: 2304; texCoords: 2304; indices: 3456)

I’m relatively new to custom meshes, but everything renders correctly so I don’t think that’s a problem.

The mesh needs to be a proper mesh consisting only of triangles. Strips etc. will not work.

Thanks, it’s fixed now!
Just a case of a mess-up in the maths. :stuck_out_tongue:

1 Like
@wukl said: Thanks, it's fixed now! Just a case of a mess-up in the maths. :P

Glad it worked out for you. What was it exactly? Maybe others run into this issue too.