fix memory leak of EntityMotionState's

This commit is contained in:
Andrew Meadows 2014-12-29 16:33:41 -08:00
parent 97f44b64fc
commit a97b8b0ea9
2 changed files with 5 additions and 1 deletions

View file

@ -37,6 +37,9 @@ EntityMotionState::EntityMotionState(EntityItem* entity)
}
EntityMotionState::~EntityMotionState() {
assert(_entity);
_entity->setPhysicsInfo(NULL);
_entity = NULL;
}
MotionType EntityMotionState::computeMotionType() const {

View file

@ -79,10 +79,10 @@ void PhysicsEngine::removeEntityInternal(EntityItem* entity) {
if (physicsInfo) {
EntityMotionState* motionState = static_cast<EntityMotionState*>(physicsInfo);
removeObject(motionState);
entity->setPhysicsInfo(NULL);
_entityMotionStates.remove(motionState);
_incomingChanges.remove(motionState);
_outgoingPackets.remove(motionState);
delete motionState;
}
}
@ -118,6 +118,7 @@ void PhysicsEngine::clearEntitiesInternal() {
QSet<EntityMotionState*>::const_iterator stateItr = _entityMotionStates.begin();
for (stateItr = _entityMotionStates.begin(); stateItr != _entityMotionStates.end(); ++stateItr) {
removeObject(*stateItr);
delete (*stateItr);
}
_entityMotionStates.clear();
_incomingChanges.clear();