Fix crash when using Physical Material with missing instance

(cherry picked from commit 5e77925492)
This commit is contained in:
Wojtek Figat
2020-12-22 11:18:00 +01:00
parent 5e239f5d87
commit 760d586923

View File

@@ -246,7 +246,7 @@ void Collider::CreateShapeBase(const PxGeometry& geometry)
const bool isTrigger = _isTrigger && CanBeTrigger(); const bool isTrigger = _isTrigger && CanBeTrigger();
const PxShapeFlags shapeFlags = GetShapeFlags(isTrigger, IsActiveInHierarchy()); const PxShapeFlags shapeFlags = GetShapeFlags(isTrigger, IsActiveInHierarchy());
PxMaterial* material = Physics::GetDefaultMaterial(); PxMaterial* material = Physics::GetDefaultMaterial();
if (Material && !Material->WaitForLoaded()) if (Material && !Material->WaitForLoaded() && Material->Instance)
{ {
material = ((PhysicalMaterial*)Material->Instance)->GetPhysXMaterial(); material = ((PhysicalMaterial*)Material->Instance)->GetPhysXMaterial();
} }
@@ -291,13 +291,10 @@ void Collider::OnMaterialChanged()
if (_shape) if (_shape)
{ {
PxMaterial* material = Physics::GetDefaultMaterial(); PxMaterial* material = Physics::GetDefaultMaterial();
if (Material) if (Material && !Material->WaitForLoaded() && Material->Instance)
{
if (!Material->WaitForLoaded())
{ {
material = ((PhysicalMaterial*)Material->Instance)->GetPhysXMaterial(); material = ((PhysicalMaterial*)Material->Instance)->GetPhysXMaterial();
} }
}
_shape->setMaterials(&material, 1); _shape->setMaterials(&material, 1);
} }
} }