Array Out of Bounds in 1.4.1; Should I upgrade? dmurphy10?

I got an ArrayIndexOutOfBoundsException on line 513 of World.java. This is in version 1.4.1b1 of Jbox2d (Via the "Download Now" link on SourceForge http://sourceforge.net/projects/jbox2d/ ... r/download).

Either I'm doing something wrong or there's a bug. Maybe I should be using what's in svn instead of the zip file? If so, should I use what's in "trunk/src" or "trunk/updating"?

The exception appeared, after I removed a body from the world. In this particular run of the simulation, I'd created and destroyed a number of bodies without problems. I do all of my body adding/removing outside of the physics step and callbacks.

What's odd is that I get a callback on my BoundaryListener telling me that the body has moved outside the bounds of the world. Especially weird since I destroyed the body.

UPDATE: Looks like I'm destroying the body twice. I must be getting multiple contact notifications.

Here's the code and stack trace:

510: // Reset island and stack.
511: island.clear();
512: int stackCount = 0;
513: stack[stackCount++] = seed;
514: seed.m_flags |= Body.e_islandFlag;

java.lang.ArrayIndexOutOfBoundsException: 0
at org.jbox2d.dynamics.World.solve(World.java:513)
at org.jbox2d.dynamics.World.step(World.java:440)
...my code from here...
at java.lang.Thread.run(Thread.java:637)
well, i had a similar problem under c++

i solved it by giving every physics object a uniqe ID and then in the callbacks building a 'objects to delete after physics step'-list based on that ID as hash value to ensure every ID is only deleted once.
The bug was mine and probably a common mistake for new-comers. You can receive multiple collision events inside the same step(). I used the same strategy as 93interactive: I gave all my objects GUIDs and skipped processing any collision between two GUIDs I'd already handled that step.
All Java objects already have UID's, though -- object identity*. You could just put them into a Set (sets don't allow two equal objects, and from memory I think the Bodys don't override the equals/hashCode methods so the equality is based on the identity of the objects)

* of course, this isn't accessible and you may need custom UID's for other things as well.
careful though, a lot of the objects are pooled, such as the contact points returned from a contact listener
You can try upgrading to the 2.0.1 release, it'll probably be faster. If you're really feeling lucky check out from subversion and see if that works.

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