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
308
308
subMesh->SetMaterial (_material, false );
309
309
}
310
310
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
+
311
318
if (this ->material && this ->ownsMaterial )
312
319
this ->Scene ()->DestroyMaterial (this ->material );
313
320
@@ -441,6 +448,13 @@ namespace gz
441
448
442
449
this ->SetMaterialImpl (_material);
443
450
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
+
444
458
if (origMaterial && origUnique)
445
459
this ->Scene ()->DestroyMaterial (origMaterial);
446
460
Original file line number Diff line number Diff line change @@ -81,6 +81,11 @@ TEST_F(MeshTest, MeshSubMesh)
81
81
submesh->SetMaterial (matClone, true );
82
82
EXPECT_NE (matClone, submesh->Material ());
83
83
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
+
84
89
// Clean up
85
90
engine->DestroyScene (scene);
86
91
}
@@ -309,6 +314,11 @@ TEST_F(MeshTest, MeshClone)
309
314
false );
310
315
}
311
316
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
+
312
322
// Clean up
313
323
engine->DestroyScene (scene);
314
324
}
You can’t perform that action at this time.
0 commit comments