I have a recursion loop that calls itself as a form of flood-fill. It calls itself until no more pixels need changing. It works great, however I get this error in the middle of my run. How do I fix this?
Error:
An unhandled exception of type 'System.StackOverflowException' occurred in System.Drawing.dll
Heres the code
The DoEvents() and the Refresh() are to slow it down and view whats going on.Code:Private Sub recurrence(ByVal x, ByVal y) myBitmap.SetPixel(x, y, Color.FromArgb(150, 150, 150, 150)) PictureBox1.Refresh() If x < blobs(1, ii) Then blobs(1, ii) = x If x > blobs(2, ii) Then blobs(2, ii) = x If y < blobs(3, ii) Then blobs(3, ii) = y If y > blobs(4, ii) Then blobs(4, ii) = y Application.DoEvents() If myBitmap.GetPixel(x + 1, y) = Color.FromArgb(255, 255, 255) Then recurrence(x + 1, y) If myBitmap.GetPixel(x - 1, y) = Color.FromArgb(255, 255, 255) Then recurrence(x - 1, y) If myBitmap.GetPixel(x, y + 1) = Color.FromArgb(255, 255, 255) Then recurrence(x, y + 1) If myBitmap.GetPixel(x, y - 1) = Color.FromArgb(255, 255, 255) Then recurrence(x, y - 1) End Sub
I found it only does this when a large area needs filling. ALOT of smaller areas do fine, so it's not total loops, just total loops in that single fill run.




Reply With Quote