Dither icon indicating copy to clipboard operation
Dither copied to clipboard

Flood fill causes stack overflow.

Open trelemar opened this issue 7 years ago • 1 comments

Here's the current function for the flood fill tool, I haven't worked alot with recursive functions and can't quite figure this one out yet. It seems to work fine with colors that aren't black and completely opaque. Also, filling a color with your current color causes a stack overflow as well.

https://github.com/trelemar/Dither/blob/master/pixelfunctions.lua#L46

function floodFill(x, y, target_color, replacement_color)
	if y <= 0 or y >= newdata:getHeight() or x <= 0 or x >= newdata:getWidth() then return
	elseif target_color == replacement_color then return
	elseif newdata:getPixel(x, y) ~= target_color then return
	else
	newdata:setPixel(x, y, replacement_color)
	floodFill(x, y + 1, target_color, replacement_color)
	floodFill(x, y - 1, target_color, replacement_color)
	floodFill(x - 1, y, target_color, replacement_color)
	floodFill(x + 1, y, target_color, replacement_color)
	return floodFill(x, y, taeget_color, replacement_color)
	end
end

trelemar avatar Jan 14 '17 13:01 trelemar

See my PR #2

MrStevns avatar May 23 '17 21:05 MrStevns