I'm trying to delete an object when a collision happens. I have put the following code in the render method of the object so it would be outside of the physics calculations.

public void render(SpriteBatch spriteBatch) {
    // some other code...

But I'm getting an run-time error which crashes the JVM and shows,

AL lib: alc_cleanup: 1 device not closed

Assertion failed!

Program: C:\Program Files\Java\jre6\bin\javaw.exe File: /var/lib/hudson/jobs/libgdx-git/workspace/gdx/jni/Box2D/Dynamics/b2World.cpp, Line 133

Expression: m_bodyCount > 0

Can anyone help me here?

  • \$\begingroup\$ it seems you are calling destroyBody() with a body count < 1. Are you sure it is being created succesfully? \$\endgroup\$
    – petervaz
    Jun 21, 2013 at 14:41
  • \$\begingroup\$ When this occures I think the only 3 possiblities are that you are destroying the body already before you call "body.getWorld().destroyBody(body);", you are destroying it while the step is occuring, or you are destroying it during a listener. Need more code to know for sure though. \$\endgroup\$ Jun 21, 2013 at 14:44

2 Answers 2


I was having the same problem. I had some edges that were being created and destroyed on the fly. It started crashing on me, and that lead me to this post. petervaz seemed to have the right idea. When I was destroying a body, I was not checking to see if it "existed" or not. For me, it was a simple check of a boolean value I had already set up.

if (on)
    on = false;

There have not been any of those crashes since I put that check in.


You must destroy your body after collision happened, for that override your EndContact() method.

  • 3
    \$\begingroup\$ Maybe explaining why MUST would be nice. \$\endgroup\$ Jun 21, 2013 at 15:06
  • \$\begingroup\$ What sm4 said - regardless of whether this solves the problem, it's of no use to anyone else without reasoning (and helping others in the future is sort of the point of SE sites). \$\endgroup\$
    – Polar
    Jun 21, 2013 at 15:56
  • \$\begingroup\$ Your answer should not be too straight forward! It has to be more guidelines or explainig WHY you need it and how. Worst answer format ever. \$\endgroup\$ Jul 12, 2013 at 6:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .