Search code examples
actionscript-3stack-overflow

StackOverflow Errors caused by flood fill: How to stop the error?


For my level editor in my game, I have a floodfill function. The map has a size of 3600 tiles (60 by 60), and I get a stack overflow error from my floodfill function (as it calls itself).

If I only floodfill a smaller radius, it works fine. How do I stop the error from occuring?

Alternatively, is there a way to tell the flash runtime to clear the stack as there is no need to return back to the function?


Solution

  • You need to make a flood fill function that doesn't rely on recursion because Flash's stack is quite limited. You can find some non-recursive ways on Wikipedia: http://en.wikipedia.org/wiki/Flood_fill#Alternative_implementations