when deserializing action, remove any existing actions that weren't part of the serialized data

This commit is contained in:
Seth Alves 2015-06-22 13:12:34 -07:00
parent f50ac9dcd5
commit 7f4e3f8216

View file

@ -1413,12 +1413,16 @@ void EntityItem::setActionData(QByteArray actionData) {
QDataStream ds(actionData);
ds >> serializedActions;
// Keep track of which actions got added or updated by the new actionData
QSet<QUuid> updated;
foreach(QByteArray serializedAction, serializedActions) {
QDataStream dsForAction(serializedAction);
EntityActionType actionType;
QUuid actionID;
dsForAction >> actionType;
dsForAction >> actionID;
updated << actionID;
if (_objectActions.contains(actionID)) {
EntityActionPointer action = _objectActions[actionID];
@ -1428,7 +1432,7 @@ void EntityItem::setActionData(QByteArray actionData) {
auto actionFactory = DependencyManager::get<EntityActionFactoryInterface>();
EntityTree* entityTree = _element ? _element->getTree() : nullptr;
EntitySimulation* simulation = entityTree? entityTree->getSimulation() : nullptr;
EntitySimulation* simulation = entityTree ? entityTree->getSimulation() : nullptr;
if (entityTree) {
EntityItemPointer entity = entityTree->findEntityByEntityItemID(_id);
@ -1438,6 +1442,24 @@ void EntityItem::setActionData(QByteArray actionData) {
}
}
}
// remove any actions that weren't included in the new data.
QHash<QUuid, EntityActionPointer>::iterator i = _objectActions.begin();
while (i != _objectActions.end()) {
const QUuid id = i.key();
if (updated.contains(id)) {
i++;
continue;
}
EntityActionPointer action = _objectActions[id];
i = _objectActions.erase(i);
action->setOwnerEntity(nullptr);
EntityTree* entityTree = _element ? _element->getTree() : nullptr;
EntitySimulation* simulation = entityTree ? entityTree->getSimulation() : nullptr;
if (simulation) {
action->removeFromSimulation(simulation);
}
}
}