From 77ea8eedb8dab989043fed4d7db6938a8c6cf54d Mon Sep 17 00:00:00 2001
From: Brad Linden <brad@lindenlab.com>
Date: Mon, 26 Jun 2023 14:07:16 -0700
Subject: [PATCH] Fix for SL-19620 & SL-19768 material overrides incorrectly
 affecting other faces

---
 indra/newview/llvocache.cpp | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/indra/newview/llvocache.cpp b/indra/newview/llvocache.cpp
index 7081ecaa4b5..a4070a513c9 100644
--- a/indra/newview/llvocache.cpp
+++ b/indra/newview/llvocache.cpp
@@ -105,7 +105,7 @@ bool LLGLTFOverrideCacheEntry::fromLLSD(const LLSD& data)
                 std::string error, warn;
                 if (override_mat->fromJSON(gltf_json_str, warn, error))
                 {
-                    mGLTFMaterial[i] = override_mat;
+                    mGLTFMaterial[side_idx] = override_mat;
                 }
                 else
                 {
@@ -126,6 +126,16 @@ bool LLGLTFOverrideCacheEntry::fromLLSD(const LLSD& data)
             LL_WARNS_IF(sides.size() != 0, "GLTF") << "broken override cache entry" << LL_ENDL;
         }
     }
+
+    llassert(mSides.size() == mGLTFMaterial.size());
+#ifdef SHOW_ASSERT
+    for (auto const & side : mSides)
+    {
+        // check that mSides and mGLTFMaterial have exactly the same keys present
+        llassert(mGLTFMaterial.count(side.first) == 1);
+    }
+#endif
+
     return true;
 }
 
@@ -141,8 +151,11 @@ LLSD LLGLTFOverrideCacheEntry::toLLSD() const
     data["object_id"] = mObjectId;
     data["local_id"] = (LLSD::Integer) mLocalId;
 
+    llassert(mSides.size() == mGLTFMaterial.size());
     for (auto const & side : mSides)
     {
+        // check that mSides and mGLTFMaterial have exactly the same keys present
+        llassert(mGLTFMaterial.count(side.first) == 1);
         data["sides"].append(LLSD::Integer(side.first));
         data["gltf_json"].append(side.second);
     }
-- 
GitLab