From 7eebc764219ceb129906400081e15499a1aec43f Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Sun, 11 Aug 2024 01:34:54 -0400 Subject: [PATCH] Program: Add crude infinite loop detection to GetRandomElementFromPool --- Rotationator/Program.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Rotationator/Program.cs b/Rotationator/Program.cs index 63a45b2..c767aa7 100644 --- a/Rotationator/Program.cs +++ b/Rotationator/Program.cs @@ -1,4 +1,4 @@ -using System.CommandLine; +using System.CommandLine; using System.CommandLine.Invocation; using System.Text.Json; using OatmealDome.BinaryData; @@ -323,10 +323,18 @@ void Run(InvocationContext context) T GetRandomElementFromPool(List pool, Func validityChecker) { T element; + int tries = 0; do { element = pool[random.Next(0, pool.Count)]; + + tries++; + + if (tries > 10000) + { + throw new Exception("Possible infinite loop detected in GetRandomElementFromPool"); + } } while (!validityChecker(element)); pool.Remove(element);