diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 3abd352778..a8f1448a3f 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -229,8 +229,9 @@ AvatarSharedPointer AvatarHashMap::newOrExistingAvatar(const QUuid& sessionUUID, AvatarSharedPointer AvatarHashMap::findAvatar(const QUuid& sessionUUID) const { QReadLocker locker(&_hashLock); - if (_avatarHash.contains(sessionUUID)) { - return _avatarHash.value(sessionUUID); + auto avatarIter = _avatarHash.find(sessionUUID); + if (avatarIter != _avatarHash.end()) { + return avatarIter.value(); } return nullptr; } diff --git a/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp b/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp index b474fb2266..da8baca95a 100644 --- a/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp @@ -358,7 +358,13 @@ void MaterialEntityRenderer::deleteMaterial(const QUuid& oldParentID, const QStr return; } - // if a remove fails, our parent is gone, so we don't need to retry + // if a remove fails, our parent is gone, so we don't need to retry, EXCEPT: + // MyAvatar can change UUIDs when you switch domains, which leads to a timing issue. Let's just make + // sure we weren't attached to MyAvatar by trying this (if we weren't, this will have no effect) + if (EntityTreeRenderer::removeMaterialFromAvatar(AVATAR_SELF_ID, material, oldParentMaterialNameStd)) { + _appliedMaterial = nullptr; + return; + } } void MaterialEntityRenderer::applyTextureTransform(std::shared_ptr& material) {