[SOLVED] Index out of range error when creating mesh shape

I’m making my own terrain system and have got the mesh creation done, now I’m trying to get collision working.

I created a MeshCollisionShape using this code here:
MeshCollisionShape terrainCollisionShape = new MeshCollisionShape(terrainTile.getMesh());
And it’s throwing this error:
java.lang.IndexOutOfBoundsException: 600 at java.base/java.nio.DirectIntBufferU.get(DirectIntBufferU.java:332) at com.jme3.scene.mesh.IndexIntBuffer.get(IndexIntBuffer.java:59) at com.jme3.bullet.util.Converter.convert(Converter.java:248) at com.jme3.bullet.collision.shapes.MeshCollisionShape.createCollisionMesh(MeshCollisionShape.java:82) at com.jme3.bullet.collision.shapes.MeshCollisionShape.<init>(MeshCollisionShape.java:77) at com.jme3.bullet.collision.shapes.MeshCollisionShape.<init>(MeshCollisionShape.java:67) at com.bootlegfireworks.terrain.Terrain.generate(Terrain.java:68) at com.bootlegfireworks.Main.generateTerrain(Main.java:82) at com.bootlegfireworks.Main.simpleInitApp(Main.java:75) at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:240) at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:139) at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:221) at java.base/java.lang.Thread.run(Thread.java:833)

Anyone have any ideas for what is causing the error?

1 Like

Thanks for providing the full stack trace.

What version of JME are you using?

What can you tell us about the terrain mesh?

  • mesh mode
  • number of vertices
  • number of indices (if any) and the size of each index, in bytes
1 Like

Mesh mode was the issue, my bad. Had it set to lines for debugging some stuff, didn’t realise it would mess with the indices data.

Removing .setMode(Mesh.Mode.Lines) when the terrain tile mesh is generated fixed the issue.

Cheers for the help and bringing up the mesh mode stuff.

1 Like

I’m also glad you were able to spot the cause and fix it.

In my opinion, failure to check the mesh mode is a bug in the com.jme3.bullet.util.Converter class, so I’m glad you brought the crash to my attention.

Two question I’m still curious about:

  1. Why use a custom mesh instead of JME’s built-in heightfield terrain?
  2. Why use jme3-jbullet physics instead of Minie?
2 Likes
  1. I’m curious how terrains are handled and generated in games so wanted to have a crack at making my own system.

  2. Didn’t know Minie was a thing! Is it advised over jm3-bullet?

Thanks!

1 Like

Didn’t know Minie was a thing! Is it advised over jm3-bullet?

Yes. Start here: https://stephengold.github.io/Minie .

1 Like