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

Discuss issues specific the Java port of Box2D
andrewbunner
Posts: 2
Joined: Thu Aug 27, 2009 8:02 am

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

Postby andrewbunner » Sun Sep 06, 2009 4:04 pm

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)

93interactive
Posts: 13
Joined: Fri Sep 04, 2009 10:22 pm
Location: Kingdom of Bavaria
Contact:

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

Postby 93interactive » Sun Sep 06, 2009 9:14 pm

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.

andrewbunner
Posts: 2
Joined: Thu Aug 27, 2009 8:02 am

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

Postby andrewbunner » Sun Sep 06, 2009 11:13 pm

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.

Villane
Posts: 101
Joined: Mon Sep 01, 2008 6:32 am

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

Postby Villane » Mon Sep 07, 2009 5:49 am

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.

toucansam
Posts: 356
Joined: Mon Jun 08, 2009 12:21 pm
Contact:

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

Postby toucansam » Tue Sep 08, 2009 4:37 am

careful though, a lot of the objects are pooled, such as the contact points returned from a contact listener

toucansam
Posts: 356
Joined: Mon Jun 08, 2009 12:21 pm
Contact:

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

Postby toucansam » Wed Sep 09, 2009 11:43 am

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.


Return to “Java”



Who is online

Users browsing this forum: No registered users and 1 guest