False infinite loop in recursive function

Hi! I am making a recursive flood fill function. the problem is that I get infinite loop after a low recursive situation (like 240 iterations or so). I added a counter for checking it and also increased the max loop in the settings to 10000000 and I still getting infinite loop.

Any help?

9/10 when I get an infinite loop, I wired something in Loop Body that should have gone off on Completed instead. The other 10% is an imperfect if while condition.

I added a counter

So it goes to 240?

2 Likes

Hi everynone!

I tried to put the function in a single image so :slight_smile:

I have my ‘pixels color’ in an integer array (it stores color ids) I added all the pixels
sequentialy in the array because Unreal dont allow multi dimensional arrays. So I have
other pure functions that make the conversion lineal to coordinates and coordinates to linear:

later I will move to C++ for performance but I don’t think that is the problem of the infinite loop.

What does FILL boolean do? Looks like its not doing anything. Is it a local variable or a function variable? Try to do this without recursion.

FILL boolean is to abort the filling…it determines if is a valid fill or not ( I just want to fill closed shapes)…if you have an open shape in any paint program and you click fill in the canvas you will just fill all the canvas. I avoid that with the FILL boolean…if fill is false then it aborts and dont fill…

I set fill to true before run the first iteration of the filling ( the root filling pixel )…then the function will iterate recursively and come back to continue…if after the ‘first function run thread’ fill is true then I can take the ‘to fill pixels queue’ and do the actual filling.

I move the pixels to fill to another ‘queue array’ and then I fill in parts with another event to avoid performance loses and infinite loops :slight_smile:

the final fill function (running time to time to update)

Try to stop the loops or the thing you are trying to do when 4x4 is done. See if it works on a smaller scale.

if filling is < about 240 bricks works perfect…I am trying to make this in a different way with events and feeding in stages but is a lot more complicated :frowning:

should not trigger infinite loop…the loop ammount is really low and fast…when I paint 200 blocks I dont miss a frame in performance (120fps) but if i paint like 240 blocks it halts with infinite loop. Obviously is a false infinite loop and increasing the max loops in settings dont do anything…Unreal should have a turn off infinite loop detection.

Try dividing it in segments and increase max loop interation to 2000000000(9 zeros).That should work.

1 Like