From fc027832003e4b1a8ea3eea800225b069819e490 Mon Sep 17 00:00:00 2001 From: Sergey Pereslavtsev Date: Fri, 28 Jan 2022 17:14:21 +0000 Subject: [PATCH 1/2] Fixed crash and asserts when heightfield is used without Terrain World Signed-off-by: Sergey Pereslavtsev --- Gems/PhysX/Code/Editor/DebugDraw.cpp | 7 ++++++- .../Code/Source/EditorHeightfieldColliderComponent.cpp | 7 ++++++- Gems/PhysX/Code/Source/HeightfieldColliderComponent.cpp | 8 +++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Gems/PhysX/Code/Editor/DebugDraw.cpp b/Gems/PhysX/Code/Editor/DebugDraw.cpp index 0af5822edf..78d216a21a 100644 --- a/Gems/PhysX/Code/Editor/DebugDraw.cpp +++ b/Gems/PhysX/Code/Editor/DebugDraw.cpp @@ -694,7 +694,12 @@ namespace PhysX const float minYBounds = -(numRows * heightfieldShapeConfig.GetGridResolution().GetY()) / 2.0f; auto heights = heightfieldShapeConfig.GetSamples(); - + + if (heights.empty()) + { + return; + } + for (int xIndex = 0; xIndex < numColumns - 1; xIndex++) { for (int yIndex = 0; yIndex < numRows - 1; yIndex++) diff --git a/Gems/PhysX/Code/Source/EditorHeightfieldColliderComponent.cpp b/Gems/PhysX/Code/Source/EditorHeightfieldColliderComponent.cpp index c6def5f0ab..292267cc5b 100644 --- a/Gems/PhysX/Code/Source/EditorHeightfieldColliderComponent.cpp +++ b/Gems/PhysX/Code/Source/EditorHeightfieldColliderComponent.cpp @@ -211,7 +211,12 @@ namespace PhysX { ClearHeightfield(); InitHeightfieldShapeConfiguration(); - InitStaticRigidBody(); + + if (!m_shapeConfig->GetSamples().empty()) + { + InitStaticRigidBody(); + } + Physics::ColliderComponentEventBus::Event(GetEntityId(), &Physics::ColliderComponentEvents::OnColliderChanged); } diff --git a/Gems/PhysX/Code/Source/HeightfieldColliderComponent.cpp b/Gems/PhysX/Code/Source/HeightfieldColliderComponent.cpp index b219253b6f..9076afeab9 100644 --- a/Gems/PhysX/Code/Source/HeightfieldColliderComponent.cpp +++ b/Gems/PhysX/Code/Source/HeightfieldColliderComponent.cpp @@ -150,7 +150,13 @@ namespace PhysX { ClearHeightfield(); InitHeightfieldShapeConfiguration(); - InitStaticRigidBody(); + + Physics::HeightfieldShapeConfiguration& configuration = static_cast(*m_shapeConfig.second); + if (!configuration.GetSamples().empty()) + { + InitStaticRigidBody(); + } + Physics::ColliderComponentEventBus::Event(GetEntityId(), &Physics::ColliderComponentEvents::OnColliderChanged); } From 8f48e4fcb6736a38f6cea6357b882846b7191d3c Mon Sep 17 00:00:00 2001 From: Sergey Pereslavtsev Date: Mon, 31 Jan 2022 11:04:13 +0000 Subject: [PATCH 2/2] Moved if section to the top Signed-off-by: Sergey Pereslavtsev --- Gems/PhysX/Code/Editor/DebugDraw.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Gems/PhysX/Code/Editor/DebugDraw.cpp b/Gems/PhysX/Code/Editor/DebugDraw.cpp index 78d216a21a..ca5d4e1694 100644 --- a/Gems/PhysX/Code/Editor/DebugDraw.cpp +++ b/Gems/PhysX/Code/Editor/DebugDraw.cpp @@ -687,12 +687,6 @@ namespace PhysX [[maybe_unused]] const AZ::Vector3& colliderScale, [[maybe_unused]] const bool forceUniformScaling) const { - const int numColumns = heightfieldShapeConfig.GetNumColumns(); - const int numRows = heightfieldShapeConfig.GetNumRows(); - - const float minXBounds = -(numColumns * heightfieldShapeConfig.GetGridResolution().GetX()) / 2.0f; - const float minYBounds = -(numRows * heightfieldShapeConfig.GetGridResolution().GetY()) / 2.0f; - auto heights = heightfieldShapeConfig.GetSamples(); if (heights.empty()) @@ -700,6 +694,12 @@ namespace PhysX return; } + const int numColumns = heightfieldShapeConfig.GetNumColumns(); + const int numRows = heightfieldShapeConfig.GetNumRows(); + + const float minXBounds = -(numColumns * heightfieldShapeConfig.GetGridResolution().GetX()) / 2.0f; + const float minYBounds = -(numRows * heightfieldShapeConfig.GetGridResolution().GetY()) / 2.0f; + for (int xIndex = 0; xIndex < numColumns - 1; xIndex++) { for (int yIndex = 0; yIndex < numRows - 1; yIndex++)