Help with an Endless Loop

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
elevationsnow
Posts: 22
Joined: Sat Sep 10, 2005 6:45 am

Help with an Endless Loop

Post by elevationsnow »

Im using the graphic headers from lua player and i wrote this function to fill an image
it works if im fill a small area
but if i try to fill a larger area it freezes up on me except it doesnt completley freeze

Code: Select all

/* simple flood fill
 * @xx location in image x
 * @yy location in image y
 * @fcolor color being replaced
 * @ncolor color replacing
 * @image image your working in
 */

Image* flood_fill(int xx, int yy, Color fcolor, Color ncolor, Image* image){
	Color current=getPixelImage(xx,yy,image);
	if&#40;current==fcolor && fcolor!=ncolor && xx>1 && xx<479 && yy>1 && yy<271&#41;
	&#123;
		putPixelImage&#40;ncolor,xx,yy,image&#41;;
		image=flood_fill&#40;xx+1,yy,fcolor,ncolor,image&#41;;
		image=flood_fill&#40;xx-1,yy,fcolor,ncolor,image&#41;;
		image=flood_fill&#40;xx,yy+1,fcolor,ncolor,image&#41;;
		image=flood_fill&#40;xx,yy-1,fcolor,ncolor,image&#41;;
	&#125;
   return image;	
&#125;
ufoz
Posts: 86
Joined: Thu Nov 10, 2005 2:36 am
Location: Tokyo
Contact:

Post by ufoz »

Stack overflow?
HaQue
Posts: 91
Joined: Fri Nov 25, 2005 8:52 am
Location: Adelaide, Australia
Contact:

Post by HaQue »

so wheres the actual loop?
charliex
Posts: 16
Joined: Thu Jan 26, 2006 4:03 pm

Post by charliex »

most likely stack overflow with the recursion

check out pal heckbert's seed fill instead, its more efficient and non recursive.. its in graphics gems 1

code is in here

ftp://ftp-graphics.stanford.edu/pub/Gra ... Gems/Gems/
bulb
Posts: 50
Joined: Thu Jan 19, 2006 10:59 pm

Post by bulb »

Obviously stack overflow. Try rewritting the function, so it uses iterative not recursive method, which in its current state is very inefficient anyway.
Post Reply