Island.add() ArrayIndexOutOfBoundsException: 1

With JBox2D 2.2.1.1 I got this error that happens randomly:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at org.jbox2d.dynamics.Island.add(Island.java:566)
at org.jbox2d.dynamics.World.solve(World.java:1013)
at org.jbox2d.dynamics.World.step(World.java:598)


When I call world.step(1.0f / 25,4,3)

All my bodies are created like this:

BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position = position;
bd.angle = (float) Math.toRadians(angle);
bd.fixedRotation = false;
bd.linearDamping = LINEAR_DAMPING;
bd.angularDamping = ANGULAR_DAMPING;
bd.bullet = true;
mainBody = world.createBody(bd);


My code perform a lot of fixture creations and deletions. Deletion is done with mainBody.createFixture().

Someone have a clue? 🙂


Thank you,
mrgibson
Try turning on assertions (run using the -ea option) to see if you're entering any illegal states.
My guess is that you might be adding/deleting bodies in contact callbacks (or other callbacks from jbox2d).
I turned the asserts on and I already found an error, thank you.

Does enabling asserts impact a lot on performance?
Hi

Same answer as in another question:

I fixed such error by adding "synchronized" to the method or around the code block that uses Box2D.
Box2D is not thread safe, and specifically on Android you tend to access it both from the UI thread (upon user events) and from the GL thread (upon draw). So you have to add the "synchronized" modifier around every block of Box2D code.

Michael

Original thread: https://box2d.org/forum/viewtopic.php?t=9501