2
\$\begingroup\$

I have a hard to debug problem. I have a Box2D game which creates a wheeled vehicle. I want the vehicle body to reflect when it goes from moving left to moving right. to do this i set a flag in a changelistener on a button and then in update method i destroy and recreate the body facing the other way. it works fine most of the time but if i flip the vehicle several times quickly JVM crashes. no errors nothing in log.

i added system.out.prints and the errors occur in the routine that instantiates the new body and before anything gets deleted/removed so i don't think the UI is trying to access null pointers. and if it was it should throw an error. M the crash seems to be at createFixture statements. but the work most of the first time. I tried debugging but the error doesn't happen much when the flips are slow. in any case createFixture drops fairly quickly into jni.

Is this a Box2D bug? Is GC the issue? From Mission Control I see the GC is collecting on a period of ooh maybe 5s and flipping slower than that mostly works.

how do i debug this?

i am win7 64bit with 64bit at and jdk7 64bit. libgdx-0.9.9 and sometimes libgdx-nightly-20140215.

\$\endgroup\$
  • 1
    \$\begingroup\$ It's really strange to have no errors at all when a crash occurs. Does the window just close without any exception being thrown? Or does it freeze? Are you able to detect when other exceptions occur? Are you using an IDE? My first guess is this: are you using any contact listeners elsewhere in your code that you're using for collision detection logic? There's a chance that after you remove the body, the fixture is still being handled in some collision code . If you try to access a destroyed body at that point, it might throw an exception. \$\endgroup\$ – midasmax May 24 '14 at 4:46
1
\$\begingroup\$

I had the same problem and I solved mine, but this might not be your problem.

What I did was, at one point to reset/cleanup:

world.dispose();
world = null;
world = new World(...);

Apparently this is no good and leads to crashing (sometimes?)

So instead I just used world.destroyBody() and whatnot, and that solved it.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.