Browse Source

Added an epsilon to the CastRay / CastShape early out condition to avoid dividing by a very small number and overflowing to INF. This can cause a float overflow exception. (#1574)

Jorrit Rouwe 5 months ago
parent
commit
5cab98f5bf
1 changed files with 2 additions and 2 deletions
  1. 2 2
      Jolt/Geometry/GJKClosestPoint.h

+ 2 - 2
Jolt/Geometry/GJKClosestPoint.h

@@ -551,7 +551,7 @@ public:
 #ifdef JPH_GJK_DEBUG
 				Trace("v . r = %g", (double)v_dot_r);
 #endif
-				if (v_dot_r >= 0.0f)
+				if (v_dot_r >= -1.0e-18f) // Instead of checking >= 0, check with epsilon as we don't want the division below to overflow to infinity as it can cause a float exception
 					return false;
 
 				// Update the lower bound for lambda
@@ -744,7 +744,7 @@ public:
 #ifdef JPH_GJK_DEBUG
 				Trace("v . r = %g", (double)v_dot_r);
 #endif
-				if (v_dot_r >= 0.0f)
+				if (v_dot_r >= -1.0e-18f) // Instead of checking >= 0, check with epsilon as we don't want the division below to overflow to infinity as it can cause a float exception
 					return false;
 
 				// Update the lower bound for lambda