コピーしたセットから溶接ジョイントを破棄するメソッド (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);
}
}
destroyWeldJoint メソッドで (createWeldJoint で) 溶接ジョイントを破棄するにはどうすればよいですか?