summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Kleshchev <andreykproductengine@lindenlab.com>2024-12-04 02:29:43 +0200
committerAndrey Kleshchev <117672381+akleshchev@users.noreply.github.com>2024-12-04 19:03:28 +0200
commit27fb297b6f5ac1e5b5e28c012a63f845eb81ab68 (patch)
treec36d2341e2f69ef45cb68ae53a256b0614b9ac8e
parent3f6d55f4fee10c5e1dc8b8f39e0560ce39e4a919 (diff)
#3190 Ensure materials are properly copied instead of reused.
-rw-r--r--indra/newview/llselectmgr.cpp42
-rw-r--r--indra/newview/llselectmgr.h2
-rw-r--r--indra/newview/lltooldraganddrop.cpp4
3 files changed, 32 insertions, 16 deletions
diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp
index 51da051340..7f1f90592f 100644
--- a/indra/newview/llselectmgr.cpp
+++ b/indra/newview/llselectmgr.cpp
@@ -2251,13 +2251,14 @@ void LLSelectMgr::selectionRevertGLTFMaterials()
// Update material locally
objectp->setRenderMaterialID(te, asset_id, false /*wait for LLGLTFMaterialList update*/);
- objectp->setTEGLTFMaterialOverride(te, nodep->mSavedGLTFOverrideMaterials[te]);
+ LLGLTFMaterial* material = new LLGLTFMaterial(*nodep->mSavedGLTFOverrideMaterials[te]);
+ objectp->setTEGLTFMaterialOverride(te, material);
// Enqueue update to server
if (asset_id.notNull())
{
// Restore overrides and base material
- LLGLTFMaterialList::queueApply(objectp, te, asset_id, nodep->mSavedGLTFOverrideMaterials[te]);
+ LLGLTFMaterialList::queueApply(objectp, te, asset_id, material);
}
else
{
@@ -3151,15 +3152,20 @@ void LLSelectMgr::adjustTexturesByScale(bool send_to_sim, bool stretch)
material->mTextureTransform[i].mScale.set(scale_x, scale_y);
}
- LLFetchedGLTFMaterial* render_mat = (LLFetchedGLTFMaterial*)tep->getGLTFRenderMaterial();
- if (render_mat)
+ const LLGLTFMaterial* base_material = tep->getGLTFMaterial();
+ if (base_material)
{
- render_mat->applyOverride(*material);
+ LLGLTFMaterial* render_material = new LLFetchedGLTFMaterial();
+ *render_material = *base_material;
+ render_material->applyOverride(*material);
+ tep->setGLTFRenderMaterial(render_material);
}
if (send_to_sim)
{
- LLGLTFMaterialList::queueModify(object, te_num, material);
+ LLGLTFMaterial new_override;
+ new_override = *material;
+ LLGLTFMaterialList::queueModify(object, te_num, &new_override);
}
}
send = send_to_sim;
@@ -5957,12 +5963,12 @@ void LLSelectMgr::processObjectProperties(LLMessageSystem* msg, void** user_data
LLGLTFMaterial* old_override = node->getObject()->getTE(i)->getGLTFMaterialOverride();
if (old_override)
{
- LLPointer<LLGLTFMaterial> mat = new LLGLTFMaterial(*old_override);
- override_materials.push_back(mat);
+ // saveGLTFMaterials will make a copy
+ override_materials.emplace_back(old_override);
}
else
{
- override_materials.push_back(nullptr);
+ override_materials.emplace_back(nullptr);
}
}
// processObjectProperties does not include overrides so this
@@ -6870,16 +6876,22 @@ void LLSelectNode::saveGLTFMaterials(const uuid_vec_t& materials, const gltf_mat
mSavedGLTFMaterialIds.clear();
mSavedGLTFOverrideMaterials.clear();
- for (uuid_vec_t::const_iterator materials_it = materials.begin();
- materials_it != materials.end(); ++materials_it)
+ for (const LLUUID& id : materials)
{
- mSavedGLTFMaterialIds.push_back(*materials_it);
+ mSavedGLTFMaterialIds.push_back(id);
}
- for (gltf_materials_vec_t::const_iterator mat_it = override_materials.begin();
- mat_it != override_materials.end(); ++mat_it)
+ for (const LLPointer<LLGLTFMaterial> &mat : override_materials)
{
- mSavedGLTFOverrideMaterials.push_back(*mat_it);
+ if (mat.notNull())
+ {
+ LLGLTFMaterial* copy = new LLGLTFMaterial(*mat);
+ mSavedGLTFOverrideMaterials.emplace_back(copy);
+ }
+ else
+ {
+ mSavedGLTFOverrideMaterials.emplace_back(nullptr);
+ }
}
}
}
diff --git a/indra/newview/llselectmgr.h b/indra/newview/llselectmgr.h
index f8242675dc..b70ec3dbea 100644
--- a/indra/newview/llselectmgr.h
+++ b/indra/newview/llselectmgr.h
@@ -198,6 +198,8 @@ public:
// final gltf material that users see.
// Ids get applied and restored by tools floater,
// overrides get applied in live material editor
+ // @param override_materials' content will be copied to not
+ // affect originals
void saveGLTFMaterials(const uuid_vec_t& materials, const gltf_materials_vec_t& override_materials);
bool allowOperationOnNode(PermissionBit op, U64 group_proxy_power) const;
diff --git a/indra/newview/lltooldraganddrop.cpp b/indra/newview/lltooldraganddrop.cpp
index 6d0704a469..6be7ec2262 100644
--- a/indra/newview/lltooldraganddrop.cpp
+++ b/indra/newview/lltooldraganddrop.cpp
@@ -1410,6 +1410,7 @@ void LLToolDragAndDrop::dropTexture(LLViewerObject* hit_obj,
LLTextureEntry* te = hit_obj->getTE(hit_face);
if (te && !remove_pbr)
{
+ // saveGLTFMaterials will make a copy
override_materials.push_back(te->getGLTFMaterialOverride());
}
else
@@ -1448,7 +1449,8 @@ void LLToolDragAndDrop::dropTexture(LLViewerObject* hit_obj,
LLTextureEntry* te = hit_obj->getTE(hit_face);
if (te && !remove_pbr)
{
- nodep->mSavedGLTFOverrideMaterials[hit_face] = te->getGLTFMaterialOverride();
+ LLGLTFMaterial* copy = new LLGLTFMaterial(*te->getGLTFMaterialOverride());
+ nodep->mSavedGLTFOverrideMaterials[hit_face] = copy;
}
else
{