I create my joint from Truck.cpp like this and everything works perfectly and responds as intended.
Then, also from Truck.cpp, I give "layer" which handles the world step and all that, a reference to the joint I want to destroy...
Then, after "layer" updates the world, I try to destroy the joint...
but I get an EXC_BAD_ACCESS error inside
at this point...
with the debugger revealing that both j->m_edgeA.prev->next and j->m_edgeA.next are NULL.
I would be super grateful for any help anyone can offer. Is this something I'm doing wrong, or possibly a bug in the Box2D code???
Code: Select all
hitch = new b2RevoluteJointDef();
hitch->Initialize(trailer, body, trailer->GetWorldCenter()+b2Vec2(0, 3));
hitch->collideConnected = false;
_world->CreateJoint(hitch);Then, also from Truck.cpp, I give "layer" which handles the world step and all that, a reference to the joint I want to destroy...
Code: Select all
if (keyCode == cocos2d::EventKeyboard::KeyCode::KEY_SPACE) {
if (hitch != NULL) {
layer->toDestroy = (b2Joint*)hitch;
}
}Then, after "layer" updates the world, I try to destroy the joint...
Code: Select all
void Main::update(float delta) {
_world->Step(delta, 10, 10);
if(toDestroy != NULL) {
_world->DestroyJoint(toDestroy);
toDestroy = NULL;
}but I get an EXC_BAD_ACCESS error inside
Code: Select all
void b2World::DestroyJoint(b2Joint* j)at this point...
Code: Select all
// Remove from body 1.
if (j->m_edgeA.prev)
{
j->m_edgeA.prev->next = j->m_edgeA.next;
}with the debugger revealing that both j->m_edgeA.prev->next and j->m_edgeA.next are NULL.
I would be super grateful for any help anyone can offer. Is this something I'm doing wrong, or possibly a bug in the Box2D code???