From f92ec30e1b7ffcf849b6739f7f963234a2e5fce5 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 26 Mar 2026 09:26:42 +0100 Subject: [PATCH] Fix crash when using convex mesh collider with negative scale #3853 --- Source/Engine/Physics/Colliders/Collider.cpp | 31 ++++++++++++------- .../Physics/PhysX/PhysicsBackendPhysX.cpp | 7 +++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Source/Engine/Physics/Colliders/Collider.cpp b/Source/Engine/Physics/Colliders/Collider.cpp index 96bd9c7ae..28588e2a6 100644 --- a/Source/Engine/Physics/Colliders/Collider.cpp +++ b/Source/Engine/Physics/Colliders/Collider.cpp @@ -209,6 +209,13 @@ void Collider::CreateShape() // Create shape const bool isTrigger = _isTrigger && CanBeTrigger(); _shape = PhysicsBackend::CreateShape(this, shape, Material, IsActiveInHierarchy(), isTrigger); + if (!_shape) + { + LOG(Error, "Failed to create physics shape for actor '{}'", GetNamePath()); + if (shape.Type == CollisionShape::Types::ConvexMesh && Float3(shape.ConvexMesh.Scale).MinValue() <= 0) + LOG(Warning, "Convex Mesh colliders cannot have negative scale"); + return; + } PhysicsBackend::SetShapeContactOffset(_shape, _contactOffset); UpdateLayerBits(); } @@ -293,18 +300,20 @@ void Collider::BeginPlay(SceneBeginData* data) if (_shape == nullptr) { CreateShape(); - - // Check if parent is a rigidbody - const auto rigidBody = dynamic_cast(GetParent()); - if (rigidBody && CanAttach(rigidBody)) + if (_shape) { - // Attach to the rigidbody - Attach(rigidBody); - } - else - { - // Be a static collider - CreateStaticActor(); + // Check if parent is a rigidbody + const auto rigidBody = dynamic_cast(GetParent()); + if (rigidBody && CanAttach(rigidBody)) + { + // Attach to the rigidbody + Attach(rigidBody); + } + else + { + // Be a static collider + CreateStaticActor(); + } } } diff --git a/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp b/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp index 02e23d890..5aba5343b 100644 --- a/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp +++ b/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp @@ -2653,10 +2653,13 @@ void* PhysicsBackend::CreateShape(PhysicsColliderActor* collider, const Collisio PxGeometryHolder geometryPhysX; GetShapeGeometry(geometry, geometryPhysX); PxShape* shapePhysX = PhysX->createShape(geometryPhysX.any(), materialsPhysX.Get(), materialsPhysX.Count(), true, shapeFlags); - shapePhysX->userData = collider; + if (shapePhysX) + { + shapePhysX->userData = collider; #if PHYSX_DEBUG_NAMING - shapePhysX->setName("Shape"); + shapePhysX->setName("Shape"); #endif + } return shapePhysX; }