уничтожение суставов box2d из скопированного набора

Я пытаюсь создать метод (destroyWeldJoint), который уничтожает сварные соединения из скопированного набора. Первоначально соединения были созданы другим методом (createWeldJoint). Причина, по которой я пытаюсь уничтожить сварные соединения в другом методе, заключается в том, что я вызываю метод createWeldJoint в методе обновления, и я хотел бы избежать попыток изменить набор при его перечислении. Пожалуйста, смотрите код ниже:

createWeldJoint:

-(void) createWeldJoint {

// using the iterator pos over the set
std::set<BodyPair *>::iterator pos;

for(pos = bodiesForJoints.begin(); pos != bodiesForJoints.end(); ++pos)
{

b2WeldJointDef      weldJointDef;

BodyPair            *bodyPair = *pos;
b2Body              *bodyA = bodyPair->bodyA;
b2Body              *bodyB = bodyPair->bodyB;weldJointDef.Initialize(bodyA,
bodyB,
bodyA->GetWorldCenter());
weldJointDef.collideConnected = false;
weldJoint = (b2WeldJoint*) world->CreateJoint(&weldJointDef);

// Free the structure we allocated earlier.
free(bodyPair);

// Remove the entry from the set.
//bodiesForJoints.erase(pos);

}

// copy of bodiesForJoints
std::set<BodyPair *> bodiesForJointsCopy(bodiesForJoints.begin(), bodiesForJoints.end());

bodiesForJoints.clear();

}

destroyWeldJoint:

- (void) destroyWeldJoint    {
std::set<BodyPair *>::iterator pos;

for(pos = bodiesForJointsCopy.begin(); pos != bodiesForJointsCopy.end(); ++pos)
{

BodyPair            *bodyPair = *pos;
b2Body              *bodyA = bodyPair->bodyA;
b2Body              *bodyB = bodyPair->bodyB;

// weldjoint should be destroyed here// Free the structure we allocated earlier.
free(bodyPair);

}
}

Как я могу уничтожить сварное соединение (в createWeldJoint) в методе destroyWeldJoint?

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector