View Single Post
  #1 (permalink)  
Old July 1st, 2005, 09:48 PM
rharris rharris is offline
Registered User
Join Date: Jun 2005
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Recursive algorithm causing stack overflow

Hi all,

I have an area fill routine that colors regions that a user clicks on (i.e. analogous to Microsoft paint's flood fill) The recursive routine works well for relatively small areas, but causes stack overflow for larger areas. See routine below:

    Private Function boundaryFill2(ByVal x As Integer, _
    ByVal y As Integer, ByVal fill As System.Drawing.Color, _
    ByVal old As System.Drawing.Color)
        Dim current As System.Drawing.Color
        If ((x <= 400) Or (x >= Me.Width - 25)) Then
            Exit Function
        ElseIf ((y <= 38) Or (y >= 300)) Then
            Exit Function
        End If
        current = m_PrintBitmap.GetPixel(x, y)
        If current.ToArgb.Equals(old.ToArgb) Then
            m_PrintBitmap.SetPixel(x, y, fill)
            PixelRecord(x, y, count) = 1
            boundaryFill2(x + 1, y, fill, old)
            boundaryFill2(x, y + 1, fill, old)
            boundaryFill2(x - 1, y, fill, old)
            boundaryFill2(x, y - 1, fill, old)
        End If
    End Function

Is there a way to increase stack size on compile? If so, how. Recursion seems like the best way to go, so I would like to stick with it. That is, unless anyone can convince me otherwise.

Any help will be greatly appreciated!


Reply With Quote