From 2d2fb5efaab2a44260d99078f11443c1dc46b3f4 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 27 Sep 2023 00:29:13 +0200 Subject: [PATCH] Fix crash if there are no surfaces in the mesh --- .../rendering/hwrenderer/data/hw_collision.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/common/rendering/hwrenderer/data/hw_collision.cpp b/src/common/rendering/hwrenderer/data/hw_collision.cpp index e83afbef6..7978750bc 100644 --- a/src/common/rendering/hwrenderer/data/hw_collision.cpp +++ b/src/common/rendering/hwrenderer/data/hw_collision.cpp @@ -55,28 +55,38 @@ TriangleMeshShape::TriangleMeshShape(const FVector3 *vertices, int num_vertices, float TriangleMeshShape::sweep(TriangleMeshShape *shape1, SphereShape *shape2, const FVector3 &target) { + if (shape1->root == -1) + return 1.0f; return sweep(shape1, shape2, shape1->root, target); } bool TriangleMeshShape::find_any_hit(TriangleMeshShape *shape1, TriangleMeshShape *shape2) { + if (shape1->root == -1) + return false; return find_any_hit(shape1, shape2, shape1->root, shape2->root); } bool TriangleMeshShape::find_any_hit(TriangleMeshShape *shape1, SphereShape *shape2) { + if (shape1->root == -1) + return false; return find_any_hit(shape1, shape2, shape1->root); } std::vector TriangleMeshShape::find_all_hits(TriangleMeshShape* shape1, SphereShape* shape2) { std::vector hits; - find_all_hits(shape1, shape2, shape1->root, hits); + if (shape1->root != -1) + find_all_hits(shape1, shape2, shape1->root, hits); return hits; } bool TriangleMeshShape::find_any_hit(TriangleMeshShape *shape, const FVector3 &ray_start, const FVector3 &ray_end) { + if (shape->root == -1) + return false; + return find_any_hit(shape, RayBBox(ray_start, ray_end), shape->root); } @@ -84,6 +94,9 @@ TraceHit TriangleMeshShape::find_first_hit(TriangleMeshShape *shape, const FVect { TraceHit hit; + if (shape->root == -1) + return hit; + // Perform segmented tracing to keep the ray AABB box smaller FVector3 ray_dir = ray_end - ray_start;