G A
G A

Reputation: 591

Brake all joints in an object in box2d

I am developing a small app on the iPad where the user can drag object together. When the objects touch, I create a distance joint that stick the objects together. This is working fine.

If the user touches the object again to drag it, I'd like to be able to move the object alone and not all the objects in the joint together. I have written the following code, but it doesn't really work:

for (b2JointEdge *jointEdge = theBody->GetJointList(); jointEdge; jointEdge=jointEdge->next) {
    b2Joint *joint = jointEdge->joint;
    _world->DestroyJoint(joint);
}

Any suggestions?

GA

Upvotes: 1

Views: 880

Answers (1)

Andrew
Andrew

Reputation: 24846

Don't remove joints while iterating the joint list. Because when a joint is removed - the list is changed and your iterators will become invalid. Save joints to an array and then remove them while iterating through your array.

Upvotes: 3

Related Questions