destroying a weldjoint created in one method in another

I am trying to make a method (destroyWeldJoint) that destroys weldjoints from a copied set. The joints were originally created in another method (createWeldJoint). Please see the code below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

-(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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- (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);

}    
}


How can I destroy the weldjoint (in createWeldJoint) in the destroyWeldJoint method?
Topic archived. No new replies allowed.