Fast contour fill algorithm?

BlitzPlus Forums/BlitzPlus Programming/Fast contour fill algorithm?

Still a stack overflow problem. Here's my code:

Function PERFORM_FILL()

	SetBuffer ImageBuffer(Picture)
	LockBuffer 
	
	FILL_COLOUR = ReadPixelFast(TURTLE_X, TURTLE_Y) 
	
	FILL( TURTLE_X, TURTLE_Y )
	
	UnlockBuffer
	SetBuffer BackBuffer()

End Function

Function FILL( xPos, yPos )

	If isSameColour( xPos, yPos )

		If xPos>=0 And xPos<=SCREEN_WIDTH And yPos>=0 And yPos<=SCREEN_HEIGHT
	
			Plot xPos, yPos
			FILL( xPos, yPos - 1 )
			FILL( xPos + 1, yPos )
			FILL( xPos, yPos + 1 )
			FILL( xPos - 1, yPos )			
	
		EndIf

	EndIf 
	
End Function

Function isSameColour( xPos, yPos )

	Return ReadPixelFast(xPos, yPos) = FILL_COLOUR

End Function


Any ideas on how to optimise this?

Thanks,

Ryan Moody