Infinite Loop Detected

I would say just have something happen before your cast so that the attempt to pull a random index has the actual potential to be different, and I would strongly suggest some kind of limiter besides just the compare. because it would be better for it to fail gracefully rather then Computer random getting you “randomly” into an infinite loop…

it can also depend on how many things might be in this array on how likely this is to be actually random, computer random does not always have full equal distribution, so for example if the array have 4 elements that are reasonable candidates, and 3 of them would loop again. it should be a 25% chance given equal distribution, but that in Computer random 25% might as well be 5%.

so by just iterating a counter before the pull, and then in you conditional check if that counter is greater then say ?10? break out into some absolute fail-state that still continues execution. where a function call is done synchronously and often on the main thread anything like this could pause the GameLoop and Tick()s that are naturally happening.

1 Like