Hi,
I seem to be misunderstanding how to destroy joints and bodies. I have an ragdoll actor with multiple members and connecting joints (revolute). When a limb/member takes enough damage, I destroy one joint and the member detaches from the main body. When a leg is damaged then it detaches from pelvis, for example. But if damaged too much, the leg body is destroyed.
So, my code basically looks like:
Code:
if (rightLegHitPoints < 0 && !rightLegDetached) {
rightLegDetached = 1;
world->DestroyJoint(rightHip);
rightHip = NULL;
}
// then later on if the detached leg continues to
// recieve damage, I destroy the leg body
if (rightLegHitPoints < -50) {
world->DestroyBody(rightLeg); // THIS LINE seems to the issue
rightLeg = NULL;
}
This call to DestroyBody seems to cause a problem when it calls
b2World::DestroyJoint in the //'Remove from the doubly linked list'
area (j->m_prev->m_next = j->m_next;). I'm guessing this happens since I already destroyed the one of the joints on the body?
What is the right way to do this? Is it my job to remove the joint from the body's joint list when I explicitly destroy the joint?
Any tips appreciated.