0
votes

I'm using AndEngine with the Box2d extension, and when my game loads its map, sometimes it crashes (yes, only sometimes. It looks so random to me) and this is what the trace looks like:

#00 pc 00014480 /data/app-lib/com.sergio.game-2/libandenginephysicsbox2dextension.so (b2Body::CreateFixture(b2FixtureDef const*)+8)
#01 pc 0000c408 /data/app-lib/com.sergio.game-2/libandenginephysicsbox2dextension.so (Java_com_badlogic_gdx_physics_box2d_Body_jniCreateFixture__JJFFFZSSS+112)
#02 pc 0001dbcc /system/lib/libdvm.so (dvmPlatformInvoke+112)
#03 pc 0004e123 /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+398)
#04 pc 00000214 /dev/ashmem/dalvik-jit-code-cache (deleted)

It won't tell me where exactly is crashing, and I don't know where to look at. I create bodies and fixtures as usual:

FixtureDef wallfixture = PhysicsFactory.createFixtureDef(0, 0, 0.2f);
wallfixture.filter.categoryBits = CATEGORY_WALL;
wallfixture.filter.maskBits = MASK_WALL;
final Body theBody = PhysicsFactory.createBoxBody(mPhysicsWorld, greenRectangle, BodyType.StaticBody, wallfixture);

Any idea?

2

2 Answers

1
votes

From my experience, there are several frequent problems with fixtures in box2d:

  1. Invalid winding order;
  2. Not convex polygon;
  3. Too small size of shape. When distance between several points is too short, box2d assumes they are one point. That's why box2d can interpret a triangle as a line, for example, which is not acceptable (polygon must have at least 3 points).

Check out if all your fixtures always math these rules. Looks like you are generating fixtures by random, and maybe sometimes some of fixtures become invalid in described meaning.

0
votes

After a lot of work, I've found what the problem was. I hope this can help people with this problem. I was creating bodies outside of the update thread, which seems not ok. So I fixed it by putting all the bodies creation on the Update thread, like this:

mEngine.runOnUpdateThread(new Runnable() {
     @Override
     public void run() {
          ...
          FixtureDef wallfixture = PhysicsFactory.createFixtureDef(0, 0, 0.2f);
          wallfixture.filter.categoryBits = CATEGORY_WALL;
          wallfixture.filter.maskBits = MASK_WALL;
          final Body theBody = PhysicsFactory.createBoxBody(mPhysicsWorld, greenRectangle, BodyType.StaticBody, wallfixture);
          ...
     }
}