Officer Vimes Officer Vimes - 2 years ago 263
Java Question

Removing a Body in Box2D (libgdx) promptly crashes the game

This is NOT being done during the world.step() method that I'm aware, and everything I found in the internet is about people doing it with collision.

I basically have it so if I press space a segment of a rope will get destroyed. Its sucesfully destroyed but the game propmptly crashes afterwards. This is what I get:

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
AL lib: (EE) alc_cleanup: 1 device not closed
Assertion failed!

Program: C:\Program Files\Java\jdk1.8.0_65\bin\java.exe

File: ./Box2D/Dynamics/b2Island.h, Line 54

Expression: m_bodyCount < m_bodyCapacity


GamePlay screen


Answer Source

I guess when you press space it destroying too fast and when there is no more rope this code causes error.


Check for segments.size()>0 when you destroying.

I also suggest

Gdx.input.isKeyJustPressed(int key)

instead of

Gdx.input.isKeyPressed(int key)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download