Inaccurate infinite loop detection

Hello,

I’ve found out that the infinite loop detection is wrong, at least I believe that it is not by design. When running multiple non-nested loops that have a total count that is larger than maximum iteration count it reports back as “infinite loop”.

When calling 5 non-nested loops, each of 250.000 iterations and hitting either begin play or call-in-editor button to call the function it will report that an infinite loop is detected (when default max iteration count is used). This is inaccurate because no loop has run more than 1.000.000 times. For in-editor pre-setup purposes, it’s possible our iteration count exceeds the max iteration count with all non-nested loops combined, and this blocks the running of in-editor pre-setup functions. I would suppose it should only trigger if a single loop node has run more than max iteration count?

Image to reproduce in 4.21 in a clean project.

I don’t believe it should only trigger if a single loop node exceeds the limit, as for example you could have a sequence of nodes, which are called over and over again, without any loop, for example recursive calls.

You can also see that UE4 does not count loop iterations (but some other internal instruction count) just by looking at the ForLoop macro: it’s a normal macro, nothing special in it.

If you trigger the MaximumLoopIterationCount, just simply increase it in the Project Settings. The naming might be ambiguous, as it is not actually working with loops, it’s probably something like this internally: “If we reach X instructions, then we’re probably in an infinite loop, so let’s stop here”.