Quellcode durchsuchen

Avoiding potential div by zero

Jorrit Rouwe vor 3 Jahren
Ursprung
Commit
faba3abbba
1 geänderte Dateien mit 4 neuen und 1 gelöschten Zeilen
  1. 4 1
      Jolt/Geometry/ClipPoly.h

+ 4 - 1
Jolt/Geometry/ClipPoly.h

@@ -34,7 +34,10 @@ void ClipPolyVsPlane(const VERTEX_ARRAY &inPolygonToClip, Vec3Arg inPlaneOrigin,
 			// Solve: (X - inPlaneOrigin) . inPlaneNormal = 0 and X = e1 + t * (e2 - e1) for X
 			// Solve: (X - inPlaneOrigin) . inPlaneNormal = 0 and X = e1 + t * (e2 - e1) for X
 			Vec3 e12 = e2 - e1;
 			Vec3 e12 = e2 - e1;
 			float denom = e12.Dot(inPlaneNormal);
 			float denom = e12.Dot(inPlaneNormal);
-			outClippedPolygon.push_back(e1 + (prev_num / denom) * e12);
+			if (denom != 0.0f)
+				outClippedPolygon.push_back(e1 + (prev_num / denom) * e12);
+			else
+				cur_inside = prev_inside; // Edge is parallel to plane, treat point as if it were on the same side as the last point
 		}
 		}
 
 
 		// Point inside, add it
 		// Point inside, add it