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?
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);
...
}
}