destroyFixture method

void destroyFixture (Fixture fixture)

Destroy a fixture. This removes the fixture from the broad-phase and destroys all contacts associated with this fixture. This will automatically adjust the mass of the body if the body is dynamic and the fixture has positive density. All fixtures attached to a body are implicitly destroyed when the body is destroyed.

@param fixture the fixture to be removed. @warning This function is locked during callbacks.

Implementation

void destroyFixture(Fixture fixture) {
  assert(world.isLocked() == false);
  if (world.isLocked() == true) {
    return;
  }

  assert(fixture._body == this);

  // Remove the fixture from this body's singly linked list.
  assert(_fixtureCount > 0);
  Fixture node = _fixtureList;
  Fixture last = null; // java change
  bool found = false;
  while (node != null) {
    if (node == fixture) {
      node = fixture._next;
      found = true;
      break;
    }
    last = node;
    node = node._next;
  }

  // You tried to remove a shape that is not attached to this body.
  assert(found);

  // java change, remove it from the list
  if (last == null) {
    _fixtureList = fixture._next;
  } else {
    last._next = fixture._next;
  }

  // Destroy any contacts associated with the fixture.
  ContactEdge edge = _contactList;
  while (edge != null) {
    Contact c = edge.contact;
    edge = edge.next;

    Fixture fixtureA = c.fixtureA;
    Fixture fixtureB = c.fixtureB;

    if (fixture == fixtureA || fixture == fixtureB) {
      // This destroys the contact and removes it from
      // this body's contact list.
      world._contactManager.destroy(c);
    }
  }

  if ((_flags & ACTIVE_FLAG) == ACTIVE_FLAG) {
    BroadPhase broadPhase = world._contactManager.broadPhase;
    fixture.destroyProxies(broadPhase);
  }

  fixture.destroy();
  fixture._body = null;
  fixture._next = null;
  fixture = null;

  --_fixtureCount;

  // Reset the mass data.
  resetMassData();
}