remove dangling shape pointers from PhysicsSimulation

This commit is contained in:
Andrew Meadows 2014-08-05 08:32:14 -07:00
parent 4d0474483d
commit a1fccdb177
3 changed files with 9 additions and 1 deletions

View file

@ -65,6 +65,9 @@ void PhysicsEntity::setEnableShapes(bool enable) {
}
void PhysicsEntity::clearShapes() {
if (_simulation) {
_simulation->removeShapes(this);
}
for (int i = 0; i < _shapes.size(); ++i) {
delete _shapes[i];
}

View file

@ -70,6 +70,7 @@ void PhysicsSimulation::removeEntity(PhysicsEntity* entity) {
if (!entity || !entity->_simulation || !(entity->_simulation == this)) {
return;
}
removeShapes(entity);
int numEntities = _entities.size();
for (int i = 0; i < numEntities; ++i) {
if (entity == _entities.at(i)) {
@ -86,7 +87,10 @@ void PhysicsSimulation::removeEntity(PhysicsEntity* entity) {
break;
}
}
// remove corresponding contacts
}
void PhysicsSimulation::removeShapes(const PhysicsEntity* entity) {
// remove data structures with pointers to entity's shapes
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
while (itr != _contacts.end()) {
if (entity == itr.value().getShapeA()->getEntity() || entity == itr.value().getShapeB()->getEntity()) {

View file

@ -32,6 +32,7 @@ public:
bool addEntity(PhysicsEntity* entity);
void removeEntity(PhysicsEntity* entity);
void removeShapes(const PhysicsEntity* entity);
/// \return true if doll was added to or is already in the list
bool addRagdoll(Ragdoll* doll);