Skip to content

Commit bf245aa

Browse files
committed
add a max depth to prevent stack overflow
1 parent eead6b9 commit bf245aa

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

osu.Game/Utils/GeometryUtils.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,11 @@ private static (Vector2, float) minCircleTrivial(ReadOnlySpan<Vector2> points)
305305
// n represents the number of points in P that are not yet processed.
306306
private static (Vector2, float) welzlHelper(List<Vector2> points, ReadOnlySpan<Vector2> r, int n)
307307
{
308+
const int max_depth = 4000;
309+
308310
// Base case when all points processed or |R| = 3
309-
if (n == 0 || r.Length == 3)
311+
// To prevent stack overflow, we stop at a certain depth and give an approximate answer
312+
if (n == 0 || r.Length == 3 || points.Count - n >= max_depth)
310313
return minCircleTrivial(r);
311314

312315
// Pick a random point randomly

0 commit comments

Comments
 (0)