From 760d5869232b517b306e9b7a26ef6ede484e6bc7 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 22 Dec 2020 11:18:00 +0100 Subject: [PATCH] Fix crash when using Physical Material with missing instance (cherry picked from commit 5e77925492addb7c226d9db2758288b3918c429d) --- Source/Engine/Physics/Colliders/Collider.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Physics/Colliders/Collider.cpp b/Source/Engine/Physics/Colliders/Collider.cpp index b00ceb925..9ddc4f1bc 100644 --- a/Source/Engine/Physics/Colliders/Collider.cpp +++ b/Source/Engine/Physics/Colliders/Collider.cpp @@ -207,7 +207,7 @@ void Collider::Attach(RigidBody* rigidBody) // Attach rigidBody->GetPhysXRigidActor()->attachShape(*_shape); - _shape->setLocalPose(PxTransform(C2P((_localTransform.Translation + _localTransform.Orientation * _center) * rigidBody->GetScale()), C2P(_localTransform.Orientation))); + _shape->setLocalPose(PxTransform(C2P((_localTransform.Translation + _localTransform.Orientation * _center) * rigidBody->GetScale()), C2P(_localTransform.Orientation))); if (rigidBody->IsDuringPlay()) rigidBody->UpdateBounds(); } @@ -246,7 +246,7 @@ void Collider::CreateShapeBase(const PxGeometry& geometry) const bool isTrigger = _isTrigger && CanBeTrigger(); const PxShapeFlags shapeFlags = GetShapeFlags(isTrigger, IsActiveInHierarchy()); PxMaterial* material = Physics::GetDefaultMaterial(); - if (Material && !Material->WaitForLoaded()) + if (Material && !Material->WaitForLoaded() && Material->Instance) { material = ((PhysicalMaterial*)Material->Instance)->GetPhysXMaterial(); } @@ -291,12 +291,9 @@ void Collider::OnMaterialChanged() if (_shape) { 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); }