在 Box2D (libgdx) 中删除 Body 会立即导致游戏崩溃

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

据我所知,这不是在 world.step() 方法中完成的,而且我在互联网上找到的所有内容都是关于人们在碰撞时这样做的。

我基本上有它所以如果我按 space 一段绳子会被破坏。它已成功销毁,但游戏随后立即崩溃。这是我得到的:

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

代码:

游戏画面 http://pastebin.com/x1x62axh

绳子 http://pastebin.com/SgtsMKKQ

我想当你按下 space 时,它破坏得太快了,当没有更多的绳子时,这段代码会导致错误。

world.destroyBody(segments.get(segments.size()-1));

销毁时检查segments.size()>0

我也建议

Gdx.input.isKeyJustPressed(int key)

而不是

Gdx.input.isKeyPressed(int key)