2

My cocos2d+box2d application freeze/stop sometimes. Pause from debugger get this line from b2World.cpp. What does it mean? Maybe problem with my contactlistener, without it app work at normal mode.

**// Clear all the island flags.
for (b2Body* b = m_bodyList; b; b = b->m_next)
{
    b->m_flags &= ~b2Body::e_islandFlag;**

My contactlistener. Detect collision -> check Filters -> push_back(body) -> add body into destroyArray -> destroy body after timestep in update method.

std::vector<b2Body *>toEat;
std::vector<MyContact>::iterator pos3;
for (pos3 = _contactListener->_contacts.begin(); pos3 != _contactListener->_contacts.end(); ++pos3) {
MyContact contact = *pos3;

b2Body *bodyA = contact.fixtureA->GetBody();
b2Body *bodyB = contact.fixtureB->GetBody();

if (bodyA->GetUserData() != NULL & bodyB->GetUserData() != NULL) {

b2Fixture *fixtureA = bodyA->GetFixtureList();

b2Filter filterA = bodyA->GetFixtureList()[0].GetFilterData();
b2Filter filterB = bodyB->GetFixtureList()[0].GetFilterData();

//some filter stuff

if (filter == my filter) {

toEat.push_back(bodyB);

   }
  }
}


std::vector<b2Body *>::iterator pos4;
for(pos4 = toEat.begin(); pos4 != toEat.end(); ++pos4) {
    b2Body *body = *pos4;
    if (body->GetUserData() != NULL) {

        CCPhysicsSprite *sprite = (CCPhysicsSprite*)body->GetUserData();
        [self removeChild:sprite cleanup:YES];
        body->SetActive(false);
        [bodiesForDestroy addObject:[NSValue valueWithPointer:body]];
    }
}

Found this link, same issue

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
flowmachine1
  • 111
  • 2
  • 7
  • OK. I solved it. If one little body with sprite fly away from screen so far and not being destroyed, you will get this freaking error. – flowmachine1 Jun 28 '14 at 23:11
  • I really doubt that is the true cause of the problem - perhaps you have just masked it by slightly changing some internal state. My guess is, you are destroying the same body twice, because the toEat vector may hold duplicates. Try using a std::set instead of std::vector. – iforce2d Jun 29 '14 at 14:06
  • iforce2d, you're right! yesterday I have change a type of my array (NSMutableArray to NSMutableOrderedSet) for destroyable bodies. – flowmachine1 Jun 30 '14 at 17:59

0 Answers0