Merge pull request #284 from SHADE-DP/Fix-Material

Fixed crash which occurs when changing the material of an object twice in a row in the inspector
This commit is contained in:
Sri Sham Haran 2022-11-25 22:34:31 +08:00 committed by GitHub
commit e20675b144
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -66,10 +66,12 @@ namespace SHADE
{ {
oldMaterial = material; oldMaterial = material;
material = {}; material = {};
oldMatIsShared = false;
} }
else if (sharedMaterial) else if (sharedMaterial)
{ {
oldMaterial = sharedMaterial; oldMaterial = sharedMaterial;
oldMatIsShared = true;
} }
// Update the material // Update the material
@ -150,7 +152,7 @@ namespace SHADE
{ {
matChanged = false; matChanged = false;
meshChanged = false; meshChanged = false;
if (oldMaterial) if (oldMaterial && !oldMatIsShared)
oldMaterial.Free(); oldMaterial.Free();
oldMaterial = {}; oldMaterial = {};
oldMesh = {}; oldMesh = {};

View File

@ -90,6 +90,7 @@ namespace SHADE
bool matChanged = true; bool matChanged = true;
Handle<SHMaterialInstance> oldMaterial; Handle<SHMaterialInstance> oldMaterial;
uint8_t lightLayer; uint8_t lightLayer;
bool oldMatIsShared = false;
RTTR_ENABLE() RTTR_ENABLE()
}; };