So I want to delete some bodies after they collide.
I have a Contact class which is a ContactListener class. In the postsolve method,
screen is my game screen, and delete is an array of bodies which I'm trying to remove:
Then I'm deleting my bodies like this:
Iterator<Body> i = delete.iterator();
Body b = i.next();
But it gives me an error: Assertion failed: (m_bodyCount < m_bodyCapacity), function Add, file ./Box2D/Dynamics/b2Island.h, line 54.
I run this code just after I set the world to step.
Step is like this: world.step(1/60f, 6, 4);
Played with the numbers, didn't help.
I also have a randomGenerate() method which generates a platform, and adds it to the world. I thought that could be the reason because the error includes the word "Add"
But the problem persisted after I removed that method, meaning I only had two bodies in the world.
I also tried setting world step to 0, adding b.setAwake(false) and b.setActive(false) but nothing changed. The problem is always the same:
Assertion failed: (m_bodyCount < m_bodyCapacity), function Add, file ./Box2D/Dynamics/b2Island.h, line 54.
Now, I have no C/C++ experience but here is the 54th line:
void Add(b2Body* body) <-- 54th line.
b2Assert(m_bodyCount < m_bodyCapacity);
body->m_islandIndex = m_bodyCount;
m_bodies[m_bodyCount] = body;
Please note that this happens even when there are only two bodies in the screen and nothing else is going on.
What can I do?