void PhysicsWorld::removeBody(PhysicsBody* body) { if (body->getWorld() != this) { CCLOG("Physics Warnning: this body doesn't belong to this world"); return; } // destory the body's joints for (auto joint : body->_joints) { // set destroy param to false to keep the iterator available removeJoint(joint, false); PhysicsBody* other = (joint->getBodyA() == body ? joint->getBodyB() : body); other->removeJoint(joint); // test the distraction is delaied or not if (_delayRemoveJoints.size() > 0 && _delayRemoveJoints.back() == joint) { joint->_destoryMark = true; } else { delete joint; } } body->_joints.clear(); removeBodyOrDelay(body); _bodies.eraseObject(body); body->_world = nullptr; }
PhysicsBody::~PhysicsBody() { for (auto it = _joints.begin(); it != _joints.end(); ++it) { PhysicsJoint* joint = *it; PhysicsBody* other = joint->getBodyA() == this ? joint->getBodyB() : joint->getBodyA(); other->removeJoint(joint); delete joint; } CC_SAFE_DELETE(_info); }
PhysicsBody::~PhysicsBody() { for (auto& joint : _joints) { PhysicsBody* other = joint->getBodyA() == this ? joint->getBodyB() : joint->getBodyA(); other->removeJoint(joint); delete joint; } if (_cpBody) { cpBodyFree(_cpBody); } }
PhysicsBody::~PhysicsBody() { for (auto it = _joints.begin(); it != _joints.end(); ++it) { PhysicsJoint* joint = *it; PhysicsBody* other = joint->getBodyA() == this ? joint->getBodyB() : joint->getBodyA(); other->removeJoint(joint); delete joint; } if (_cpBody) { cpBodyFree(_cpBody); } }