First of all, I have to say that this Color Filling algorithm is really not efficient at all but it should work, I don't understand why it can raise a StackOverflowException (occurred in System.Drawing.dll), here is the code:
private void Fill(Point p, Color backColor)
if (drawing.GetPixel(p.X, p.Y) == backColor)
drawing.SetPixel(p.X, p.Y, penColor);
Fill(new Point(p.X + 1, p.Y), backColor);
Fill(new Point(p.X , p.Y + 1), backColor);
Fill(new Point(p.X - 1, p.Y), backColor);
Fill(new Point(p.X , p.Y - 1), backColor);
penColor is the color I want to fill with, the line in bold is where the IDE highlighted to inform the exception. The method Fill is called in a mousedown event handler of a panel (of course I already had some enclosed line to test the Fill() method)
Could you please show me why the code can raise a StackOverflowException (occurs in System.Drawing.dll)?
Your help would be highly appreciated!