World in TestbedTest needs a "ground body"

Discuss issues specific the Java port of Box2D
Posts: 1
Joined: Tue Sep 22, 2015 2:37 pm

World in TestbedTest needs a "ground body"

Postby Ente » Tue Sep 22, 2015 3:49 pm

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:

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

  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(
at org.jbox2d.dynamics.World.solve(
at org.jbox2d.dynamics.World.step(
at org.jbox2d.testbed.framework.TestbedTest.step(
at org.jbox2d.testbed.framework.TestbedTest.update(
at ch.duckpond.universe.test.physics.UniverseTest.update(
at org.jbox2d.testbed.framework.TestbedController.update(

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 add a "ground body" to every testbed world:

    Code: Select all

    BodyDef bodyDef = new BodyDef();
    groundBody = m_world.createBody(bodyDef);
    So I tried adding an empty body to my test. Which also solves the issue.

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

Return to “Java”

Who is online

Users browsing this forum: No registered users and 1 guest