Problem with world.DestroyJoint()

Compiling, Linking, and Debugging C++ Box2D
Posts: 2
Joined: Sat Sep 27, 2014 6:23 am

Problem with world.DestroyJoint()

Postby evanbarmes » Mon Mar 13, 2017 7:57 pm

I create my joint from Truck.cpp like this and everything works perfectly and responds as intended.

Code: Select all

hitch = new b2RevoluteJointDef();
    hitch->Initialize(trailer, body, trailer->GetWorldCenter()+b2Vec2(0, 3));
    hitch->collideConnected = false;

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) {
        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->;

with the debugger revealing that both j->m_edgeA.prev->next and j-> 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???

Return to “Build Issues”

Who is online

Users browsing this forum: No registered users and 1 guest