Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » A crash..

This thread is locked; no one can reply to it. rss feed Print
A crash..
type568
Member #8,381
March 2007
avatar

My problem is that this code crashes. It was originally using _putpixel32, that's why it called fastfloodfill32. I know that it's slow, but my idea was to make it myself, with a putpixel. So I changed it to putpixel, and now I'm totally confused.
As I know putpixel, can't crash a program, while it's bitmap does exist.

Also, commenting ANY one of the two summons each fastfloodfill_32_**direction** summons, solves the crash problem (Than the function doesn't do what is required of it though).

I spent hourse on commenting different parts, looking threw the code and I can't understand what is the problem. It seems like the problem, is in the closed circle. (summon 1 by 1 east,north,west, south,east..) It should freeze than though, not crash. (I noticed that before, while was trying to do the same with 8 directions, untill understood that 8 aren't nessasary, and even worse).

1 
2#include "Graphics.h"
3 
4//fastfloodfill568_32
5void fastfloodfill568_32_north(BITMAP* dest,int x,int y);
6void fastfloodfill568_32_west(BITMAP* dest,int x,int y);
7void fastfloodfill568_32_south(BITMAP* dest,int x,int y);
8void fastfloodfill568_32_east(BITMAP* dest,int x,int y);
9 
10int c_fff568,p_fff568; //BITMAP* ....
11 
12void fastfloodfill568_32_east(BITMAP* dest,int x,int y)
13 {
14 _putpixel(dest,x,y,c_fff568);
15 
16 if(dest->w>x+1)
17 if(_getpixel32(dest,x+1,y)==p_fff568)
18 fastfloodfill568_32_east(dest,x+1,y);
19 if(0<y-1)
20 if(_getpixel32(dest,x,y-1)==p_fff568)
21 fastfloodfill568_32_north(dest,x,y-1);
22 }
23 
24void fastfloodfill568_32_north(BITMAP* dest,int x,int y)
25 {
26 putpixel(dest,x,y,c_fff568);
27
28 if(0<y-1)
29 if(_getpixel32(dest,x,y-1)==p_fff568)
30 fastfloodfill568_32_north(dest,x,y-1);
31 if(0<x-1)
32 if(_getpixel32(dest,x-1,y)==p_fff568)
33 fastfloodfill568_32_west(dest,x-1,y);
34 }
35 
36void fastfloodfill568_32_west(BITMAP* dest,int x,int y)
37 {
38 putpixel(dest,x,y,c_fff568);
39 
40 
41 if(0<x-1)
42 if(_getpixel32(dest,x-1,y)==p_fff568)
43 fastfloodfill568_32_west(dest,x-1,y);
44 if(dest->h>y+1)
45 if(_getpixel32(dest,x,y+1)==p_fff568)
46 fastfloodfill568_32_south(dest,x,y+1);
47 }
48 
49void fastfloodfill568_32_south(BITMAP* dest,int x,int y)
50 {
51 putpixel(dest,x,y,c_fff568);
52 
53 if(dest->h>y+1)
54 if(_getpixel32(dest,x,y+1)==p_fff568)
55 fastfloodfill568_32_south(dest,x,y+1);
56 if(dest->w>x+1)
57 if(_getpixel32(dest,x+1,y)==p_fff568)
58 fastfloodfill568_32_east(dest,x+1,y);
59 }
60 
61 
62void fastfloodfill568_32(BITMAP* dest,int x,int y,int clr)
63 {
64 c_fff568=clr;
65
66 if(x>0 && y>0 && x<dest->w && y<dest->h)
67 {
68 p_fff568=getpixel(dest,x,y);
69 if(p_fff568 == c_fff568)
70 return;
71 putpixel(dest,x,y,c_fff568);
72 }
73 else
74 return;
75 
76 acquire_bitmap(dest);
77 if(dest->w>x+1)
78 if(_getpixel32(dest,x+1,y)==p_fff568)
79 fastfloodfill568_32_east(dest,x+1,y);
80 
81 if(0<y-1)
82 if(_getpixel32(dest,x,y-1)==p_fff568)
83 fastfloodfill568_32_north(dest,x,y-1);
84 
85 if(0<x-1)
86 if(_getpixel32(dest,x-1,y)==p_fff568)
87 fastfloodfill568_32_west(dest,x-1,y);
88 
89 
90 if(dest->h>y+1)
91 if(_getpixel32(dest,x,y+1)==p_fff568)
92 fastfloodfill568_32_south(dest,x,y+1);
93 
94 release_bitmap(dest);
95 }

This code crashes in different programs, while allgro floodfill works.
Another problem though, is the floodfill's leaks, allegro's floodfill leaks from my 4 cornered forms. (They are drawn with a loop, using only four dots, in some cases leaks).

Edit:

Graphics.h:

#define USE_CONSOLE
#include <allegro.h>

void fastfloodfill568_32(BITMAP* dest,int x,int y,int color); 
void fastline568_32(BITMAP* buff,int x,int y,int x1,int y1,int color);

Onewing
Member #6,152
August 2005
avatar

Quote:

This code crashes in different programs, while allgro floodfill works.
Another problem though, is the floodfill's leaks, allegro's floodfill leaks from my 4 cornered forms. (They are drawn with a loop, using only four dots, in some cases leaks).

Use floodfill. It'll work better. Just make sure you fill an enclosed space.

Two, using _getpixel32 will crash if it gets a pixel outside of the bitmap and you'll need to be in 32 bit color mode.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

type568
Member #8,381
March 2007
avatar

getpixel() still crashes. Actually I have this code working with polygon, and I want to compare performance with _putpixel. Also I have it working with pure lines(without fill..).

By the way, the program is a 3d cube, twisting.. And i want to do it with putpixel :].

Go to: