Message-ID: <8D53104ECD0CD211AF4000A0C9D60AE3015CAC48@probe-2.acclaim-euro.net> From: Shawn Hargreaves To: djgpp AT delorie DOT com Subject: Re: Allegro problem Date: Thu, 26 Aug 1999 15:19:39 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.0.1460.8) Content-Type: text/plain Reply-To: djgpp AT delorie DOT com Carl Marg writes: > The funny thing is it will seem to work right for a fraction of a > second, but a bit into the fill, it will crash. [...] > void boundfill(int x, int y, int fill, int bound) > { > int cur; > cur=getpixel(screen,x,y); > if ((cur!=bound) && (cur!=fill)) > { > putpixel(screen,x,y,fill); > boundfill(x+1,y,fill,bound); > boundfill(x-1,y,fill,bound); > boundfill(x,y+1,fill,bound); > boundfill(x,y-1,fill,bound); > } //if > } You are probably running out of stack space: this single pixel recursive algorithm will use an insane amount of stack for anything other than very tiny areas. You can implement this far more efficiently if you do the filling in terms of horizontal scanline segments rather than as individual pixels, but even after you do that, it would probably be better to use dynamically allocated memory rather than recursion (because even with a very smart algorithm, there are still some situations that will recurse too deeply and overflow your stack). Foley & Van Damme, "Principles and Practice of Computer Graphics" has a decent section about floodfill algorithms, or you could look at the Allegro source file flood.c for a working implementation. Shawn Hargreaves.