Recursive calls, stacks and flood fill

Franky this is the first time I am working with recursive functions and attempting to do a flood fill algorithm.
The problem I think is the recursive function calls, It ends up as an infinite loop. I’m guessing it is a limit of 250 stacks, as I have read at various places.
I have tried with smaller fills and they work, but as I make them bigger, they end up with the infinite loop warning.
Is there a way to increase the stack size? Or how would I go about doing a flood fill without reaching this limit?

So I went away from using recursive calls to creating my own stack, reading the stack during an ever increasing loop.


So it basically works now, except that I wish to do this flood fill very often, since it is supposed to be like an air leak or something. And this is very performance heavy.


As seen in the picture, once the flood fills starts, performance is horrible.
The calls, 691, is how many times cells attempt to add themselves to the stack.
By using a TSet, I check if a cell is in the Tset, if it is not - add it to the set and to the stack. If is, drop it. So most of them, 558, are dropped.
133 is how many cells that are affected by the flood fill so the size of the stack that Is looped through.

This amount of calls, is that good or bad? I mean, I have to query somehow if they have been processed or not. And each cell has to check 8way cells. I tried adding a boolean to the cells instead but it’s the same result.

Can this at all be performant enough to do like 10 times/s?

With the concept being that any cell may cause an air leak, and of course a map that consists of these cells, any other methods to achieve this?