From 2a4ca80887157efdaac00b326ec0fcadb7cd3427 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@bred.dog>
Date: Sun, 11 Aug 2019 08:28:58 -0400
Subject: [PATCH] Oops I broke releasing textures

---
 indra/newview/llviewertexturelist.cpp | 16 ++++++++++++----
 indra/newview/llviewertexturelist.h   |  6 +++---
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp
index c464b2934c..ec89778b2d 100644
--- a/indra/newview/llviewertexturelist.cpp
+++ b/indra/newview/llviewertexturelist.cpp
@@ -624,7 +624,7 @@ void LLViewerTextureList::findTexturesByID(const LLUUID &image_id, std::vector<L
 
 LLViewerFetchedTexture *LLViewerTextureList::findImage(const LLTextureKey &search_key)
 {
-    const auto& iter = mUUIDHashMap.find(search_key);
+    auto iter = mUUIDHashMap.find(search_key);
     if (iter == mUUIDHashMap.cend())
         return NULL;
     return iter->second;
@@ -677,7 +677,7 @@ void LLViewerTextureList::removeImageFromList(LLViewerFetchedTexture *image)
 			<< " but doesn't have mInImageList set"
 			<< " ref count is " << image->getNumRefs()
 			<< LL_ENDL;
-		const auto& iter = mUUIDHashMap.find(LLTextureKey(image->getID(), (ETexListType)image->getTextureListType()));
+		auto iter = mUUIDHashMap.find(LLTextureKey(image->getID(), (ETexListType)image->getTextureListType()));
 		if(iter == mUUIDHashMap.cend())
 		{
 			LL_INFOS() << "Image  " << image->getID() << " is also not in mUUIDMap!" << LL_ENDL ;
@@ -720,8 +720,16 @@ void LLViewerTextureList::addImage(LLViewerFetchedTexture *new_image, ETexListTy
 	sNumImages++;
 
 	addImageToList(new_image);
-	mUUIDMap.emplace(key, new_image);
-	mUUIDHashMap.emplace(key, new_image);
+	auto uuidm_pair = mUUIDMap.try_emplace(key, new_image);
+	if (!uuidm_pair.second && uuidm_pair.first != mUUIDMap.cend())
+	{
+		uuidm_pair.first->second = new_image;
+	}
+	auto uuidhm_pair = mUUIDHashMap.try_emplace(key, new_image);
+	if (!uuidhm_pair.second && uuidhm_pair.first != mUUIDHashMap.cend())
+	{
+		uuidhm_pair.first->second = new_image;
+	}
 	new_image->setTextureListType(tex_type);
 }
 
diff --git a/indra/newview/llviewertexturelist.h b/indra/newview/llviewertexturelist.h
index 58880904a0..30469e09fa 100644
--- a/indra/newview/llviewertexturelist.h
+++ b/indra/newview/llviewertexturelist.h
@@ -223,9 +223,9 @@ public:
     
 private:
     using uuid_map_t = std::map< LLTextureKey, LLPointer<LLViewerFetchedTexture> >;
-	using uuid_hash_map_t = absl::flat_hash_map< LLTextureKey, LLPointer<LLViewerFetchedTexture> >;
+    using uuid_hash_map_t = absl::flat_hash_map< LLTextureKey, LLViewerFetchedTexture* >;
     uuid_map_t mUUIDMap;
-	uuid_hash_map_t mUUIDHashMap;
+    uuid_hash_map_t mUUIDHashMap;
     LLTextureKey mLastUpdateKey;
     LLTextureKey mLastFetchKey;
 	
@@ -282,7 +282,7 @@ private:
 		LLRect mImageClipRegion;
 	};
 
-	typedef std::map< std::string, LLPointer<LLUIImage> > uuid_ui_image_map_t;
+	typedef absl::flat_hash_map< std::string, LLPointer<LLUIImage> > uuid_ui_image_map_t;
 	uuid_ui_image_map_t mUIImages;
 
 	//
-- 
GitLab