exception: org.jbox2d.collision.BroadPhase.query(BroadPhase)

Hi, i'm making a game with a lot of bodies loaded dinamically, so I cannot control easily them
but sometimes the game got stuck from this exception:
Code:
Exception in thread "Thread principale" java.lang.ArrayIndexOutOfBoundsException: -1
   at org.jbox2d.collision.BroadPhase.query(BroadPhase.java:778)
   at org.jbox2d.collision.BroadPhase.createProxy(BroadPhase.java:254)
   at org.jbox2d.collision.Shape.createProxy(Shape.java:302)
   at org.jbox2d.dynamics.Body.createShape(Body.java:205)
   

This happen SOMETIMES when i try to create some body, what could be the problem?
oh the only difference from the created bodies is the position.

and some times I got another strange error, when i launch world.query to know what object are near a body
and i get the some error:
Code:
Exception in thread "Thread principale" java.lang.ArrayIndexOutOfBoundsException: -1
   at org.jbox2d.collision.BroadPhase.query(BroadPhase.java:778)

when it happens, I think it's made only (i suppose) from static bodies, and it appear in my GUI as a missing piece of the wall or the floor

what can generate this kind of error?? thx!
These tend to be nasty little hard-to-track down problems that come up because something in the broadphase became inconsistent somehow. Sometimes this means that you've deleted a shape twice, IIRC, or possibly that you've held on to a reference to a deleted shape and tried to use it in an overlap test, or something like that.

I would definitely first check out any of your code that deletes bodies/shapes, and make absolutely sure that after they are deleted there's no way to touch them again (i.e. they're removed from all of your lists, you're not holding on to references to them, etc.).

Also, please try running your program with the JVM arg -ea, which enables assertions (you can also use -enableassertions) - it may be the case that something is going wrong earlier, and if an assertion is triggered it might give a better idea where the problem is.

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