Java – Box2d & Libgdx Contact listener and inactive Bodies

Box2d & Libgdx Contact listener and inactive Bodies… here is a solution to the problem.

Box2d & Libgdx Contact listener and inactive Bodies

I’m developing a project using libgdx, box2d in Java.

Here’s what my program does :

_ When 2 fixtures collide, set the Body of one of the fixtures to non-“Activity”

   myBody.setActive(false);

Question:

I

noticed that when I put this line, I received a fatal signal 11 (SIGSEGV) at 0x00000004 (code=1) in logcat, probably because the non-activity body is still in ContactListener.

I only have 1 ContactListener class in my main program.

How do I remove/add a Body to ContactListener?
I don’t know if this is the solution, but I thought, can you help me? I don’t know how to fix this.

Solution

That’s because contact handling in the listener happens in world.step, and the world is blocked at runtime.

For example, you can add it to a list to make it inactive after world.step ends.

Related Problems and Solutions