more dtor cleanup of back pointers

This commit is contained in:
Andrew Meadows 2014-06-19 11:57:32 -07:00
parent 9950c5b209
commit 828c365b25
2 changed files with 9 additions and 2 deletions

View file

@ -10,6 +10,8 @@
//
#include "PhysicsEntity.h"
#include "PhysicsSimulation.h"
#include "Shape.h"
#include "ShapeCollider.h"
@ -23,8 +25,10 @@ PhysicsEntity::PhysicsEntity() :
}
PhysicsEntity::~PhysicsEntity() {
// entity should be removed from the simulation before it is deleted
assert(_simulation == NULL);
if (_simulation) {
_simulation->removeEntity(this);
_simulation = NULL;
}
}
void PhysicsEntity::setTranslation(const glm::vec3& translation) {

View file

@ -31,11 +31,14 @@ PhysicsSimulation::PhysicsSimulation() : _collisionList(MAX_COLLISIONS_PER_SIMUL
}
PhysicsSimulation::~PhysicsSimulation() {
// entities have a backpointer to this simulator that must be cleaned up
int numEntities = _entities.size();
for (int i = 0; i < numEntities; ++i) {
_entities[i]->_simulation = NULL;
}
_entities.clear();
// but Ragdolls do not
_dolls.clear();
}