diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1a4d2db83e..5fc3bad8e5 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -6756,8 +6756,10 @@ void Application::updateWindowTitle() const { } void Application::clearDomainOctreeDetails() { + // before we delete all entities get MyAvatar's AvatarEntityData ready + getMyAvatar()->prepareAvatarEntityDataForReload(); - // if we're about to quit, we really don't need to do any of these things... + // if we're about to quit, we really don't need to do the rest of these things... if (_aboutToQuit) { return; } @@ -6785,9 +6787,6 @@ void Application::clearDomainOctreeDetails() { ShaderCache::instance().clearUnusedResources(); DependencyManager::get()->clearUnusedResources(); DependencyManager::get()->clearUnusedResources(); - - // we just deleted all of MyAvatar's AvatarEntities so we flag it to reload from settings - getMyAvatar()->rememberToReloadAvatarEntityDataFromSettings(); } void Application::domainURLChanged(QUrl domainURL) { diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 2fb265dfbd..af748a14c0 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1501,8 +1501,8 @@ void MyAvatar::updateAvatarEntities() { // We collect changes to AvatarEntities and then handle them all in one spot per frame: updateAvatarEntities(). // Basically this is a "transaction pattern" with an extra complication: these changes can come from two - // "directions" and the "authoritative source" of each direction is different, so maintain two distinct sets of - // transaction lists; + // "directions" and the "authoritative source" of each direction is different, so we maintain two distinct sets + // of transaction lists: // // The _entitiesToDelete/Add/Update lists are for changes whose "authoritative sources" are already // correctly stored in _cachedAvatarEntityBlobs. These come from loadAvatarEntityDataFromSettings() and @@ -1690,10 +1690,7 @@ bool MyAvatar::updateStaleAvatarEntityBlobs() const { return false; } - std::set staleBlobs; - _avatarEntitiesLock.withWriteLock([&] { - staleBlobs = std::move(_staleCachedAvatarEntityBlobs); - }); + std::set staleBlobs = std::move(_staleCachedAvatarEntityBlobs); int32_t numFound = 0; for (const auto& id : staleBlobs) { bool found = false; @@ -1717,9 +1714,20 @@ bool MyAvatar::updateStaleAvatarEntityBlobs() const { return true; } -void MyAvatar::rememberToReloadAvatarEntityDataFromSettings() { - AvatarEntityMap emptyMap; - setAvatarEntityData(emptyMap); +void MyAvatar::prepareAvatarEntityDataForReload() { + saveAvatarEntityDataToSettings(); + + _avatarEntitiesLock.withWriteLock([&] { + _packedAvatarEntityData.clear(); + _entitiesToDelete.clear(); + _entitiesToAdd.clear(); + _entitiesToUpdate.clear(); + _cachedAvatarEntityBlobs.clear(); + _cachedAvatarEntityBlobsToDelete.clear(); + _cachedAvatarEntityBlobsToAddOrUpdate.clear(); + _cachedAvatarEntityBlobUpdatesToSkip.clear(); + }); + _reloadAvatarEntityDataFromSettings = true; } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 44f0c29b0b..38cef264a7 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -1187,7 +1187,7 @@ public: glm::vec3 getNextPosition() { return _goToPending ? _goToPosition : getWorldPosition(); } void updateAvatarEntities() override; - void rememberToReloadAvatarEntityDataFromSettings(); + void prepareAvatarEntityDataForReload(); /**jsdoc * Create a new grab. @@ -1614,7 +1614,6 @@ signals: */ void disableHandTouchForIDChanged(const QUuid& entityID, bool disable); - private slots: void leaveDomain(); void updateCollisionCapsuleCache(); @@ -1980,7 +1979,7 @@ private: std::vector _cachedAvatarEntityBlobUpdatesToSkip; // // Also these lists for tracking delayed changes to blobs and Settings - std::set _staleCachedAvatarEntityBlobs; + mutable std::set _staleCachedAvatarEntityBlobs; // // keep a ScriptEngine around so we don't have to instantiate on the fly (these are very slow to create/delete) QScriptEngine* _myScriptEngine { nullptr };