i got a weird bug: Sometimes the engine throws an infinite loop error.
Sometimes because:
the function works most of the times
the error only gets thrown with larger inputs or if called in some static loops
the function works perfectly fine with small inputs
Even weirder: The call stack leads to the default UE5 branch node/macro.
The function that uses the branch also only has loops that terminate after a fixed amount (no dynamic loops or anything). I even tried hard-capping the amount of loop iterations, but the error persists.
How does a branch can be infinite?
How does a function can be sometimes infinite sometimes not?
Do i have to supress the error? (If yes how?)
If you need code help me let me know, but i didnt even know where to start with this.
try to break your code into fewer parts, i believe it the while loop that causing the issue and add some print string to see how many times you are actually looping.
for example, only test the while loop first, if it does x10 print string, then you can test further with the first for loop…
all your loop in the same execution line get add together including ue5 default macro for loop, that why the error pop up there because it reach the limit of iteration.
This is not a bug. If you trigger the infinite loop error you get the callstack that was executing whenever the runaway threshold was reached. Depending on what happens in your game, what other actors are present etc. this may not always be the exact same location. However it should more or less trigger in a place that is most frequently executing (i.e. has the highest probability to be executing when the limit is reached).
I explained some of the technical details under the hood in this thread here which also contains a few potential solutions. With the CellsToCheck you seem to have an array variable already so your’s isn’t exactly the same problem but most should still be applicable.
With the Loop until the queue is empty you should already be mostly setup to early out from the loop even before the queue is empty based on a simple maximum number of entries to process per call. Then you can just continue the next tick until the queue is actually empty by simply calling the function again.
Using delays does not work because calling a delay multiple times has no effect. I also tried using a custom delay-for loop but it really messes with the max loop index. (Max index will sometimes be ignored).
So how do i do a working delay node inside a nested for-loop?
If i just use my custom delay-for loop (that works for a single for-loop) it will run out out the last index for some reason.
Wanted output:
0 0
0 1
1 0
1 1
The output i get with a delay in the for loop (even if i set the delay to 0):
0 0
1 1
1 0
2 0
3 1
My macro (like all the tutorials out there suggest):
Like i said there is no real infinte loop. The maximum number of steps is around ~250 - ~300 wich is no problem for smaller maps. As soon as i try bigger maps i get a (false) infinite loop error
Alright i doubled the max iteration count and it works for now. Altough the real issue is not really solved i can at least look at the numbers now. Marking this as resolved!