attempt some clean-ups in edge/unexpected situations

This commit is contained in:
Seth Alves 2015-06-27 11:09:28 -07:00
parent 4ce3465bf7
commit c0c1116c69
3 changed files with 16 additions and 2 deletions

View file

@ -88,6 +88,13 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert
}
EntityItem::~EntityItem() {
// clear out any left-over actions
EntityTree* entityTree = _element ? _element->getTree() : nullptr;
EntitySimulation* simulation = entityTree ? entityTree->getSimulation() : nullptr;
if (simulation) {
clearActions(simulation);
}
// these pointers MUST be correct at delete, else we probably have a dangling backpointer
// to this EntityItem in the corresponding data structure.
assert(!_simulated);
@ -1450,7 +1457,8 @@ void EntityItem::setActionData(QByteArray actionData) {
if (_objectActions.contains(actionID)) {
EntityActionPointer action = _objectActions[actionID];
// XXX make sure types match?
// TODO: make sure types match? there isn't currently a way to
// change the type of an existing action.
action->deserialize(serializedAction);
} else {
auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>();

View file

@ -27,6 +27,13 @@ void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar delta
if (!_active) {
return;
}
if (_ownerEntity.expired()) {
qDebug() << "warning -- action with no entity removing self from btCollisionWorld.";
btDynamicsWorld* dynamicsWorld = static_cast<btDynamicsWorld*>(collisionWorld);
dynamicsWorld->removeAction(this);
return;
}
updateActionWorker(deltaTimeStep);
}

View file

@ -443,7 +443,6 @@ EntityActionPointer PhysicsEngine::getActionByID(const QUuid& actionID) const {
return nullptr;
}
void PhysicsEngine::addAction(EntityActionPointer action) {
assert(action);
const QUuid& actionID = action->getID();