File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
include/gz/rendering/base Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -308,6 +308,13 @@ namespace gz
308308 subMesh->SetMaterial (_material, false );
309309 }
310310
311+ // If the same material is being set, return early and don't try
312+ // to destroy the material. We still need call SetMaterial on the
313+ // submeshes in case the user changed some material properties
314+ // before setting it back.
315+ if (!_unique && _material == this ->material )
316+ return ;
317+
311318 if (this ->material && this ->ownsMaterial )
312319 this ->Scene ()->DestroyMaterial (this ->material );
313320
@@ -441,6 +448,13 @@ namespace gz
441448
442449 this ->SetMaterialImpl (_material);
443450
451+ // If the same material is being set, return early and don't try
452+ // to destroy the material. We still need to call SetMaterialImpl
453+ // above in case the user changed some material properties
454+ // before setting it back.
455+ if (!_unique && _material == origMaterial)
456+ return ;
457+
444458 if (origMaterial && origUnique)
445459 this ->Scene ()->DestroyMaterial (origMaterial);
446460
Original file line number Diff line number Diff line change @@ -81,6 +81,11 @@ TEST_F(MeshTest, MeshSubMesh)
8181 submesh->SetMaterial (matClone, true );
8282 EXPECT_NE (matClone, submesh->Material ());
8383
84+ // Setting the same material but do not clone
85+ MaterialPtr newMatClone = submesh->Material ();
86+ submesh->SetMaterial (newMatClone, false );
87+ EXPECT_EQ (newMatClone, submesh->Material ());
88+
8489 // Clean up
8590 engine->DestroyScene (scene);
8691}
@@ -309,6 +314,11 @@ TEST_F(MeshTest, MeshClone)
309314 false );
310315 }
311316
317+ // Setting the same material but do not clone
318+ MaterialPtr newMatClone = clonedMesh->Material ();
319+ clonedMesh->SetMaterial (newMatClone, false );
320+ EXPECT_EQ (newMatClone, clonedMesh->Material ());
321+
312322 // Clean up
313323 engine->DestroyScene (scene);
314324}
You can’t perform that action at this time.
0 commit comments