make sure to lock data

This commit is contained in:
Dante Ruiz 2017-07-17 22:11:05 +01:00
parent 282b364fad
commit 21d760a533
3 changed files with 9 additions and 1 deletions

View file

@ -2366,6 +2366,12 @@ AvatarEntityMap AvatarData::getAvatarEntityData() const {
return result;
}
void AvatarData::insertDetachedEntityID(const QUuid entityID) {
_avatarEntitiesLock.withWriteLock([&] {
_avatarEntityDetached.insert(entityID);
});
}
void AvatarData::setAvatarEntityData(const AvatarEntityMap& avatarEntityData) {
if (avatarEntityData.size() > MAX_NUM_AVATAR_ENTITIES) {
// the data is suspect

View file

@ -615,7 +615,7 @@ public:
Q_INVOKABLE AvatarEntityMap getAvatarEntityData() const;
Q_INVOKABLE void setAvatarEntityData(const AvatarEntityMap& avatarEntityData);
void setAvatarEntityDataChanged(bool value) { _avatarEntityDataChanged = value; }
void insertDetachedEntityID(const QUuid entityID) { _avatarEntityDetached.insert(entityID); }
void insertDetachedEntityID(const QUuid entityID);
AvatarEntityIDs getAndClearRecentlyDetachedIDs();
// thread safe

View file

@ -502,6 +502,8 @@ void EntityScriptingInterface::deleteEntity(QUuid id) {
AvatarSharedPointer myAvatar = avatarHashMap->getAvatarBySessionID(myNodeID);
if (entity->getClientOnly() && entity->getOwningAvatarID() != myNodeID) {
// don't delete other avatar's avatarEntities
// If you actually own the entity but the onwership is not set because of a domain switch
// the line below make sure the entity is deleted.
myAvatar->insertDetachedEntityID(id);
shouldDelete = false;
return;