I've been getting a lot of random exceptions like this coming from somewhere inside the library... I thought it was a threading problem, so I rewrote the program to do all the body adds/removes/changes in the same thread as the physics. However, now it crashes MORE often than before! I really have no idea what to do, help please.
Random ArrayIndexOutOfBoundsExceptions
Javaplease post the code where you are not using thread, runnable or timer. And also the error trace
This will help a lot
This will help a lot
Code:
java.lang.ArrayIndexOutOfBoundsException: 60
at org.jbox2d.dynamics.Island.add(Island.java:91)
at org.jbox2d.dynamics.World.solve(World.java:629)
at org.jbox2d.dynamics.World.step(World.java:471)
at com.mynet.buildsim.World.doPhysics(World.java:111)
at com.mynet.buildsim.Buildsim.main(Buildsim.java:141)
at org.jbox2d.dynamics.Island.add(Island.java:91)
at org.jbox2d.dynamics.World.solve(World.java:629)
at org.jbox2d.dynamics.World.step(World.java:471)
at com.mynet.buildsim.World.doPhysics(World.java:111)
at com.mynet.buildsim.Buildsim.main(Buildsim.java:141)
Code:
java.lang.ArrayIndexOutOfBoundsException: 2147483647
at org.jbox2d.collision.BroadPhase.moveProxy(BroadPhase.java:459)
at org.jbox2d.collision.Shape.synchronize(Shape.java:239)
at org.jbox2d.dynamics.Body.synchronizeShapes(Body.java:710)
at org.jbox2d.dynamics.World.solve(World.java:672)
at org.jbox2d.dynamics.World.step(World.java:471)
at com.mynet.buildsim.World.doPhysics(World.java:111)
at com.mynet.buildsim.Buildsim.main(Buildsim.java:141)
at org.jbox2d.collision.BroadPhase.moveProxy(BroadPhase.java:459)
at org.jbox2d.collision.Shape.synchronize(Shape.java:239)
at org.jbox2d.dynamics.Body.synchronizeShapes(Body.java:710)
at org.jbox2d.dynamics.World.solve(World.java:672)
at org.jbox2d.dynamics.World.step(World.java:471)
at com.mynet.buildsim.World.doPhysics(World.java:111)
at com.mynet.buildsim.Buildsim.main(Buildsim.java:141)
Code:
java.lang.ArrayIndexOutOfBoundsException: -1
at org.jbox2d.collision.BroadPhase.moveProxy(BroadPhase.java:458)
at org.jbox2d.collision.Shape.synchronize(Shape.java:239)
at org.jbox2d.dynamics.Body.synchronizeShapes(Body.java:710)
at org.jbox2d.dynamics.World.solve(World.java:672)
at org.jbox2d.dynamics.World.step(World.java:471)
at com.mynet.buildsim.World.doPhysics(World.java:111)
at com.mynet.buildsim.Buildsim.main(Buildsim.java:141)
at org.jbox2d.collision.BroadPhase.moveProxy(BroadPhase.java:458)
at org.jbox2d.collision.Shape.synchronize(Shape.java:239)
at org.jbox2d.dynamics.Body.synchronizeShapes(Body.java:710)
at org.jbox2d.dynamics.World.solve(World.java:672)
at org.jbox2d.dynamics.World.step(World.java:471)
at com.mynet.buildsim.World.doPhysics(World.java:111)
at com.mynet.buildsim.Buildsim.main(Buildsim.java:141)
This is a physics sandbox, so it's quite complex and hard to post code. The crashes I noticed are on the intro scene, which does the following quite rapidly via a lua script: removes joints, deletes bodies when they fall out of the world, and makes objects non-collidable using a ContactFilter.
I think the speed at which it is doing stuff could be a problem, because before I fixed the threading issue, the calls to the engine were made from the lua thread (might have been happening while the world was trying to step.) Now, they are queued and done all at once by the main thread after each frame.
I just noticed an infinite loop/deadlock problem as well, here is the stack trace from my debugger (looks to be related to bodies being deleted)

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