Results 1 to 14 of 14

Thread: Getting recursion error in loop!

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Getting recursion error in loop!

    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
    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
    The DoEvents() and the Refresh() are to slow it down and view whats going on.

    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.
    Last edited by MotoMan_Yz400; Aug 10th, 2007 at 04:00 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width