java.lang.ArrayIndexOutOfBoundsException: -1

Oh, and I don't know much about which JAR is the latest JAR, because like I said, I just link to .class files that Eclipse builds out of the raw source code, which (the source code) is presumably the most up-to-date representation of JBox2D that exists. But I do know that just today, when I tried to use the JBox2D that was in the zip file offered on SourceForge instead of the one from SVN that I'd been using, I ran into many problems, due to changes in the code between the two versions. So, it may be that if you do want to use the latest version, then you'll have to update your own project a bit. The changes didn't appear to me to be very big, though... mostly it was just that Shape and some related types had moved from one namespace to another. I just went into Eclipse and pressed Ctrl-Shift-O a lot and it mostly worked itself out. (But then I ended up switching back to the SVN source code anyway because I guess that's the latest version AND THEREFORE CLEARLY THE BEST hm yes.)
Thank you =D, using SVN worked perfectly, and there are no errors in the code. I use the class files from the bin folder now instead of the jar. Everything seems good, but I still get errors =/:

Code:
Exception in thread "Thread-6" java.lang.ArrayIndexOutOfBoundsException: -1
   at org.jbox2d.collision.BroadPhase.query(BroadPhase.java:764)
   at org.jbox2d.collision.BroadPhase.destroyProxy(BroadPhase.java:396)
   at org.jbox2d.collision.shapes.Shape.destroyProxy(Shape.java:346)
   at org.jbox2d.dynamics.Body.synchronizeShapes(Body.java:972)
   at org.jbox2d.dynamics.World.solve(World.java:791)
   at org.jbox2d.dynamics.World.step(World.java:577)
   at Game.run(Game.java:368)
   at java.lang.Thread.run(Unknown Source)


Code:
Exception in thread "Thread-6" java.lang.ArrayIndexOutOfBoundsException: -1
   at org.jbox2d.collision.BroadPhase.moveProxy(BroadPhase.java:458)
   at org.jbox2d.collision.shapes.Shape.synchronize(Shape.java:258)
   at org.jbox2d.dynamics.Body.synchronizeShapes(Body.java:961)
   at org.jbox2d.dynamics.World.solve(World.java:791)
   at org.jbox2d.dynamics.World.step(World.java:577)
   at Game.run(Game.java:368)
   at java.lang.Thread.run(Unknown Source)


I added the -ea option to the VM arguments, but I don't know where I can see which assertions are tripped, so I couldn't find out any more about these errors.
Assert statements in Java just throw exceptions, of type AssertionError or some such, when they're violated. So if your program violated an assertion before reaching the ArrayIndexOutOfBoundsException, then it would have crashed earlier, and it would have produced a different report. Assuming you're doing everything right--and there's not much to do other than put in that -ea option--then your program isn't violating an assertion.

Except... the failing code you quote below asserts that the array index is not negative before using it. So that assertion should fail, and if that one is failing to fail, then maybe some important assertions somewhere else are also failing to fail (so to speak), even earlier. But maybe that assertion isn't in the version of the code you're using now? You could run your program in debugging mode and have Eclipse break when an ArrayIndexOutOfBoundsException is thrown, to learn more about what's happening....

You could also stick the statement
assert false;
into some part of your program that definitely runs, in order to test whether assertion errors are working, and then get back to the original problem.

On assertion: http://java.sun.com/j2se/1.4.2/docs/gui ... ssert.html

(I'd just tell you how to fix your original problem, but I don't know that.)
Are you creating body from different thread? If yes, are you sure to synchronize it well? now that you have SVN source code, can you try to find the error^^
In you case the errors are:
(BroadPhase.java: from 457 to 460)
Code:
for ( int axis = 0; axis < 2; ++axis) {
   oldValues.lowerValues[axis] = m_bounds[axis][proxy.lowerBounds[axis]].value;
   oldValues.upperValues[axis] = m_bounds[axis][proxy.upperBounds[axis]].value;
}

and
(BroadPhase.java:764)
Code:
if ( bounds[i].isLower()) {


Are you using polygons and maybe you have modified the number of maximal vertices? Or are you destroying body from another thread? Can you create a simple example that reproduce the error?
Bye
I just got an assertion error =D:
Code:
Exception in thread "Thread-6" java.lang.AssertionError
   at org.jbox2d.collision.BroadPhase.testOverlap(BroadPhase.java:175)
   at org.jbox2d.collision.BroadPhase.moveProxy(BroadPhase.java:563)
   at org.jbox2d.collision.shapes.Shape.synchronize(Shape.java:258)
   at org.jbox2d.dynamics.Body.synchronizeShapes(Body.java:961)
   at org.jbox2d.dynamics.World.solve(World.java:791)
   at org.jbox2d.dynamics.World.step(World.java:577)
   at Game.run(Game.java:323)
   at java.lang.Thread.run(Unknown Source)

And this is the assertion that was tripped:
Code:
   assert (p.upperBounds[axis] < 2 * m_proxyCount);

variables:
Code:
Proxy  (id=40)   
   categoryBits   0   
   groupIndex   0
   lowerBounds    (id=1707)   
      [0]   41   
      [1]   2   
   maskBits   0   
   overlapCount   0   
   timeStamp   0   
   upperBounds    (id=1726)   
      [0]   52   
      [1]   4   
   userData   PolygonShape  (id=1727)
huh... I'm really not sure here, are you doing anything weird with the engine? Can you give me anything to recreate this?
I'm getting the same errors: viewtopic.php?p=22822#p22822
i just noticed something while trying to generate some code for you. in the run() function of a Thread is the following code:
Code:
         level.step(TIMESTEP, NUMITERATIONS);
         if (Game.GENERATECODE && time == 0) {
            System.out.println("for(int i = 0; i < 200; i++)");
            System.out.println("world.step("+TIMESTEP+", "+NUMITERATIONS+");");
         }
         time++;

which outputs the following:

for(int i = 0; i < 200; i++)
for(int i = 0; i < 200; i++)
world.step(0.033333335, 100);
world.step(0.033333335, 100);

so I guess I also make 2 calls to world.step() simultaneously. But I don't know why =/
Weltall 7 wrote:
so I guess I also make 2 calls to world.step() simultaneously. But I don't know why =/


You could try putting a breakpoint on your step() call, to see what threads are reaching that point. Although, examining threads in a debugger is kind of tricky sometimes.

You could stick in one of these at that point, to tell you more about which thread is doing what:
new Throwable().printStackTrace()
Thank you for your advice, everything works perfectly now and the result is always the same =).
I accidentally creaded a thread twice, once in the init() function of the applet and another time in the start() function.

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