Weird crash when trying to destroy joints.

Hello

I am trying to destroy the joints which attaches my player to a motorcycle, if i call the destroyjoint functions the program crashes about 1 percent of the time, it has worked on two occasions, and when i set breakpoints in the RemovePlayerFromBike() function everything works out properly, otherwise when it breaks it tells me that the joints are already nulled. I never call any references to the joints in any other places in the game other that these two functions.I have no idea why this happens, here is a snippet of the code, would really appreciate some feedback on this matter.





void Player::RemovePlayerFromBike()
{
if(myAllowJointDestruction == true);
{
myWorld->DestroyJoint(myDisAttJoint4);
myDisAttJoint4 = NULL;
myWorld->DestroyJoint(myDisAttJoint3);
myDisAttJoint3 = NULL;
myWorld->DestroyJoint(myDisAttJoint2);
myDisAttJoint2 = NULL;
myWorld->DestroyJoint(myDisAttJoint1);
myDisAttJoint1 = NULL;
myWorld->DestroyJoint(myAttachmentJoint1);
myAttachmentJoint1 = NULL;
myAllowJointDestruction = false;
myPlayerFallenOff = true;
}
}


void Player::AttachPlayerToBike()
{
myAttachmentJointDef1.Initialize(myTorso, myBike.GetMainBody(), b2Vec2( myBike.GetMainBody()->GetWorldCenter().x-0.2f, myBike.GetMainBody()->GetWorldCenter().y-0.9f));
myAttachmentJointDef1.lowerAngle = -0.45f;
myAttachmentJointDef1.upperAngle = 0.4f;
myAttachmentJointDef1.enableLimit = true;
myAttachmentJointDef1.enableMotor = true;
myAttachmentJointDef1.collideConnected = false;
myAttachmentJoint1 = dynamic_cast<b2RevoluteJoint*>(myWorld->CreateJoint(&myAttachmentJointDef1));

//////////AttachArms
myDisAttJointDef1.Initialize(myLowerArm1, myBike.GetMainBody(),b2Vec2(myLowerArm1->GetWorldCenter().x+0.15f, myLowerArm1->GetWorldCenter().y), b2Vec2( myBike.GetMainBody()->GetWorldCenter().x+0.5, myBike.GetMainBody()->GetWorldCenter().y-1.1));
myDisAttJointDef1.length = 0.04f;
myDisAttJointDef1.collideConnected = false;
myDisAttJoint1 = reinterpret_cast<b2DistanceJoint*>(myWorld->CreateJoint(&myDisAttJointDef1));

myDisAttJointDef2.Initialize(myLowerArm2, myBike.GetMainBody(),b2Vec2(myLowerArm2->GetWorldCenter().x+0.15f, myLowerArm2->GetWorldCenter().y), b2Vec2( myBike.GetMainBody()->GetWorldCenter().x+0.5, myBike.GetMainBody()->GetWorldCenter().y-1.1));
myDisAttJointDef2.length = 0.04f;
myDisAttJointDef2.collideConnected = false;
myDisAttJoint2 = reinterpret_cast<b2DistanceJoint*>(myWorld->CreateJoint(&myDisAttJointDef2));

////////AttachLegs
myDisAttJointDef3.Initialize(myCalf1, myBike.GetMainBody(),b2Vec2(myCalf1->GetWorldCenter().x-0.15f, myCalf1->GetWorldCenter().y), b2Vec2( myBike.GetMainBody()->GetWorldCenter().x+0.4, myBike.GetMainBody()->GetWorldCenter().y-0.3));
myDisAttJointDef3.dampingRatio = 0.8f;
myDisAttJointDef3.frequencyHz = 20.9f;
myDisAttJointDef3.length = 0.05f;
myDisAttJointDef3.collideConnected = false;
myDisAttJoint3 = reinterpret_cast<b2DistanceJoint*>(myWorld->CreateJoint(&myDisAttJointDef3));

myDisAttJointDef4.Initialize(myCalf2, myBike.GetMainBody(),b2Vec2(myCalf2->GetWorldCenter().x-0.15f, myCalf2->GetWorldCenter().y), b2Vec2( myBike.GetMainBody()->GetWorldCenter().x+0.4, myBike.GetMainBody()->GetWorldCenter().y-0.3));
myDisAttJointDef4.dampingRatio = 0.8f;
myDisAttJointDef4.frequencyHz = 20.9f;
myDisAttJointDef4.length = 0.05f;
myDisAttJointDef4.collideConnected = false;
myDisAttJoint4 = reinterpret_cast<b2DistanceJoint*>(myWorld->CreateJoint(&myDisAttJointDef4));

}
as before, problem solved, confusion due to brain damage, i got to stop doing this =)

Original thread: https://box2d.org/forum/viewtopic.php?t=6215