Problem with Box2D (EXC_BAD_ACCESS) on world->Step

Hello,

I'm developing my first game using cocos2d-x and Box2D, and im in end of game development. However at this time i have a critical bug: If i fire too much bullets (with touch of user on the display of the iphone) and this bullets shoot enemies consecutively (making collisions) i'm getting an EXC_BAD_ACESS on world_->Step after some collision.

When i detect an collision i'm removing the body (as u can see in the code that i will post bellow).

Follow the error i found that the error are end in this code inside void* b2BlockAllocator::Allocate(int32 size):


Code:
m_freeLists[index] = block->next;



That is my code for update my game scene:

Code:
void GameScene::update(float dt) {
    world_->Step(dt, 8, 3);

    std::vector<b2Body*> toDestroy;

    // Updates all objects positions.
    for (size_t i = 0; i < objects_->count(); i++)
    {
        Object *object = (Object*) objects_->objectAtIndex(i);
        object->update(dt);
        if (!VisibleRect::getVisibleRect().containsPoint(object->getPosition()))
        {
            toDestroy.push_back(object->getBody());
        }
    }

    // Loop through all of the box2d bodies that are currently colliding, that we have
    // gathered with our custom contact listener...
    std::vector<ContactData>::iterator pos;
    for (pos = contact_listener_->_contacts.begin(); pos != contact_listener_->_contacts.end(); ++pos)
    {
        ContactData contact = *pos;

        // Get the box2d bodies for each object
        b2Body *bodyA = contact.fixtureA->GetBody();
        b2Body *bodyB = contact.fixtureB->GetBody();
        if (bodyA->GetUserData() != NULL && bodyB->GetUserData() != NULL)
        {
            Object *objectA = (Object *) bodyA->GetUserData();
            Object *objectB = (Object *) bodyB->GetUserData();

            // Bullet vs Enemy
            if (objectA->getTag() == Object::kPlayerBullet && objectB->getTag() == Object::kEnemy)
            {
                toDestroy.push_back(bodyA);
                toDestroy.push_back(bodyB);
            }
            // Enemy vs Bullet
            else if (objectA->getTag() == Object::kEnemy && objectB->getTag() == Object::kPlayerBullet)
            {
                toDestroy.push_back(bodyB);
                toDestroy.push_back(bodyA);
            }

        }
    }

    // Loop through all of the box2d bodies we wnat to destroy...
    std::vector<b2Body*>::iterator destroyIt;
    for (destroyIt = toDestroy.begin(); destroyIt != toDestroy.end(); ++destroyIt)
    {
        b2Body *body = *destroyIt;
        Object *object = (Object *) body->GetUserData();

        world_->DestroyBody(body);
        this->removeChild(object, true);
        objects_->removeObject(object, true);
    }
}


I'm using this collision detector: http://www.cocos2d-x.org/forums/6/topics/3160

What i'm doing wrong? Anyone can help please?
Hello,

I already solve the problem.
To help the community here comes the solution:

i'm adding 2 times the same body to the contact list.
Using std::set instead of std::vector is a quick way to avoid this, because the set will keep the contents unique.

Original thread: https://box2d.org/forum/viewtopic.php?t=9698