fix theoretical crash bug in editEntity()

This commit is contained in:
Andrew Meadows 2015-06-01 13:59:56 -07:00
parent 2400f5c000
commit fa491a5c4f
2 changed files with 23 additions and 22 deletions

View file

@ -129,37 +129,38 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit
return results; return results;
} }
QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& properties) { QUuid EntityScriptingInterface::editEntity(QUuid id, EntityItemProperties properties) {
EntityItemID entityID(id); EntityItemID entityID(id);
// If we have a local entity tree set, then also update it. // If we have a local entity tree set, then also update it.
if (_entityTree) { if (_entityTree) {
_entityTree->lockForWrite(); _entityTree->lockForWrite();
_entityTree->updateEntity(entityID, properties); bool updatedEntity = _entityTree->updateEntity(entityID, properties);
_entityTree->unlock(); _entityTree->unlock();
}
// make sure the properties has a type, so that the encode can know which properties to include if (updatedEntity) {
if (properties.getType() == EntityTypes::Unknown) { _entityTree->lockForRead();
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
if (entity) { if (entity) {
// we need to change the outgoing properties, so we make a copy, modify, and send. // make sure the properties has a type, so that the encode can know which properties to include
EntityItemProperties modifiedProperties = properties; properties.setType(entity->getType());
entity->setLastBroadcast(usecTimestampNow()); if (properties.hasTerseUpdateChanges()) {
modifiedProperties.setType(entity->getType()); // we make a bid for (or assert) our simulation ownership
if (modifiedProperties.hasTerseUpdateChanges()) { auto nodeList = DependencyManager::get<NodeList>();
// we make a bid for (or assert) our simulation ownership const QUuid myNodeID = nodeList->getSessionUUID();
auto nodeList = DependencyManager::get<NodeList>(); properties.setSimulatorID(myNodeID);
const QUuid myNodeID = nodeList->getSessionUUID();
modifiedProperties.setSimulatorID(myNodeID); if (entity->getSimulatorID() == myNodeID) {
// we think we already own the simulation, so make sure to send ALL TerseUpdate properties
if (entity->getSimulatorID() == myNodeID) { entity->getAllTerseUpdateProperties(properties);
// we think we already own simulation, so make sure we send ALL TerseUpdate properties }
entity->getAllTerseUpdateProperties(modifiedProperties);
} }
entity->setLastBroadcast(usecTimestampNow());
} }
queueEntityMessage(PacketTypeEntityEdit, entityID, modifiedProperties); _entityTree->unlock();
queueEntityMessage(PacketTypeEntityEdit, entityID, properties);
return id; return id;
} }
return QUuid();
} }
queueEntityMessage(PacketTypeEntityEdit, entityID, properties); queueEntityMessage(PacketTypeEntityEdit, entityID, properties);

View file

@ -78,7 +78,7 @@ public slots:
/// edits a model updating only the included properties, will return the identified EntityItemID in case of /// edits a model updating only the included properties, will return the identified EntityItemID in case of
/// successful edit, if the input entityID is for an unknown model this function will have no effect /// successful edit, if the input entityID is for an unknown model this function will have no effect
Q_INVOKABLE QUuid editEntity(QUuid entityID, const EntityItemProperties& properties); Q_INVOKABLE QUuid editEntity(QUuid entityID, EntityItemProperties properties);
/// deletes a model /// deletes a model
Q_INVOKABLE void deleteEntity(QUuid entityID); Q_INVOKABLE void deleteEntity(QUuid entityID);