From 562458200cb2c69268b28d9556e26e42c02ddc04 Mon Sep 17 00:00:00 2001 From: Slartibarty Date: Tue, 11 Apr 2023 07:15:10 +0100 Subject: [PATCH] If we fail to create a convex hull from the supplied points, substitute it for a small sphere. I found exactly one model in a single map for gmod that causes this to happen, a better solution would be to re-calculate a valid hull from the supplied points, but this'll do since it's such a rare case. --- vphysics_jolt/vjolt_collide.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/vphysics_jolt/vjolt_collide.cpp b/vphysics_jolt/vjolt_collide.cpp index 7960b9b..226438a 100644 --- a/vphysics_jolt/vjolt_collide.cpp +++ b/vphysics_jolt/vjolt_collide.cpp @@ -535,7 +535,20 @@ namespace ivp_compat settings.mHullTolerance = 0.0f; JPH::ConvexShape *pConvexShape = ShapeSettingsToShape< JPH::ConvexShape >( settings ); if ( !pConvexShape ) - return nullptr; + { + // Wow that sucks, just mock up a small sphere to subsitute. + // This can happen for models with extremely broken collision hulls. + // If we don't do this, we'll crash later on because older versions of Source are missing + // an important nullptr check. + // A better solution would be to generate a valid convex hull from the points provided. + JPH::SphereShapeSettings sphereSettings( 1.0f ); + pConvexShape = ShapeSettingsToShape< JPH::ConvexShape >( sphereSettings ); + if ( !pConvexShape ) + { + // This should never fail, but catching anyway + return nullptr; + } + } pConvexShape->SetUserData( pLedge->client_data ); return pConvexShape;