For my project Universe I try to persist jbox2d entities in mongodb. Source code of the Test I'm talking about can be found here:
Jbox2d release: 2.2.1.1
When testing a first working version in the testbed I tried to load a world from mongo to a TestbedTest. Which means after loading I've to set a World for a TestbedTest. As the TestbedTest does not support a setter for m_world I've to come up with a rather hacky solution in my TestbedClass:
This seemed to work just fine until i started interacting with the simulation by dragging around some of the bodys after they first collided. Then I got:
or the corresponding IndexOutOfBounds exception without assertions. After some investigation I noticed that:
Is this intended behaviour, did I miss something in the documentation about this?
If not: can somebody explain why this happens?
This users says that:
So could this Issue be caused by a race condition of the simulation & GUI thread in the Testbed?
thank you
Jbox2d release: 2.2.1.1
When testing a first working version in the testbed I tried to load a world from mongo to a TestbedTest. Which means after loading I've to set a World for a TestbedTest. As the TestbedTest does not support a setter for m_world I've to come up with a rather hacky solution in my TestbedClass:
Code: Select all
@Override
public void init(final World argWorld, final boolean argDeserialized) {
// hacky: set world from persisted world
m_world = persistedWorld.get(DATASTORE);
super.init(m_world, argDeserialized);
}
This seemed to work just fine until i started interacting with the simulation by dragging around some of the bodys after they first collided. Then I got:
Exception in thread "Testbed" java.lang.AssertionError
at org.jbox2d.dynamics.Island.add(Island.java:564)
at org.jbox2d.dynamics.World.solve(World.java:1013)
at org.jbox2d.dynamics.World.step(World.java:598)
at org.jbox2d.testbed.framework.TestbedTest.step(TestbedTest.java:601)
at org.jbox2d.testbed.framework.TestbedTest.update(TestbedTest.java:552)
at ch.duckpond.universe.test.physics.UniverseTest.update(UniverseTest.java:126)
at org.jbox2d.testbed.framework.TestbedController.update(TestbedController.java:203)
at org.jbox2d.testbed.framework.TestbedController.run(TestbedController.java:330)
at java.lang.Thread.run(Thread.java:745)
or the corresponding IndexOutOfBounds exception without assertions. After some investigation I noticed that:
- Dragging a Body before all the bodies collide hides the issue
- The following lines in TestbedTest.java@210 add a "ground body" to every testbed world:So I tried adding an empty body to my test. Which also solves the issue.
Code: Select all
BodyDef bodyDef = new BodyDef();
groundBody = m_world.createBody(bodyDef);
Is this intended behaviour, did I miss something in the documentation about this?
If not: can somebody explain why this happens?
This users says that:
I fixed such error by adding "synchronized" to the method or around the code block that uses Box2D.
So could this Issue be caused by a race condition of the simulation & GUI thread in the Testbed?
thank you