Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » draw_sprite() crash

This thread is locked; no one can reply to it. rss feed Print
draw_sprite() crash
JMonteiro .
Member #7,296
May 2006

Simple as that. when i call the function draw_sprite it simply crashes my code. I've read lots of posts with that problem and i haven't found the answer.
The program is ok, but i've tested it with some fprintf's and it crashes exactly on the first draw_sprite. here's some code:

1int allegro(){
2
3 //piped = (int *)malloc(sizeof(int));
4
5 allegro_init();
6 install_keyboard();
7 install_mouse();
8 enable_hardware_cursor();
9
10 set_color_depth(32);
11 set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
12 show_mouse(NULL);
13 //char buf[128];
14
15
16 buffer = create_bitmap( 640, 480); //cria fundo como bitmap para todas as variacoes
17 //serem feitas no bitmap e nao no ecra
18
19 clear_to_color( buffer, makecol( 9, 183, 48)); //set do background
20
21 arrowBOT = load_bitmap("arrow.bmp",NULL);
22 BOTSprite = load_bitmap("BOT.bmp",NULL);
23 BOTSecundario = load_bitmap("BOT2.bmp",NULL);
24 obstaculo = load_bitmap("obstaculo.bmp",NULL);
25 rato = load_bitmap("rato2.bmp",NULL);
26 
27 
28 show_mouse(buffer);
29 set_mouse_sprite(rato);
30 set_mouse_sprite_focus(0,0);
31 //coordenadas iniciais do bot
32 x=295;
33 y=215;
34get_refresh_rate();
35 //blit(buffer, screen, 0, 0, mouse_x, mouse_y, 640, 480);
36 
37cursor_x = 0;
38cursor_y = 0;
39 
40 //incrementa - decrementa velocidade KEY_TILDE KEY_MINUS
41 while (idle != 0){
42 
43
44 //getMouseInfo();
45
46 textout_ex(buffer,font,"..::RAC BOT tester::..",25,15,makecol(255,255,255),makecol(9,183,48));
47 
48//imprime variaveis
49 textprintf(buffer, font, 150,460, makecol(255,255,255), "X = %d", x);
50 textprintf(buffer, font, 250,460, makecol(255,255,255), "Y = %d", y);
51 textprintf(buffer, font, 350,460, makecol(255,255,255), "Velocidade = %d", vel);
52
53 fprintf(stderr,"x = %d || y = %d || Vel = %d || Angle = %d \n",x,y,vel,ammount);
54//
55 
56 //linhas verticais
57 line( buffer,25,0,25,480, makecol(255,255,255));
58 line (buffer, 612,0,612,680,makecol(255,255,255));
59//linhas horizontais
60 line (buffer,0,25,680,25,makecol(255,255,255));
61 line (buffer, 0,450,680,450,makecol(255,255,255));
62 
63 
64 
65 
66 
67acquire_screen();
68//ERROR---------------
69 draw_sprite(screen,BOTSecundario,x-7,y-10);
70 fprintf(stderr,"CHAMOU1");
71 
72 draw_sprite(buffer,obstaculo, 150,100);
73 draw_sprite (buffer,rato,cursor_x,cursor_y);
74 
75 //draw_sprite (buffer,BOTSprite,x,y);
76 rotate_sprite(buffer, BOTSprite, x, y, itofix(ammount));
77
78 draw_sprite (buffer,arrowBOT,550,400); //escreve as setas

the error is right there where it's commented ERROR.
Anny ideas what the heck it is? Please, try to be specific, if you want more info, i'll give it to you.
By the way, I'm working under linux (MEPIS) compiling with gcc.
Thank you...

miran
Member #2,407
June 2002

Check the return value of load_bitmap.

--
sig used to be here

JMonteiro .
Member #7,296
May 2006

The arrowBOT = load_bitmap("arrow.bmp",NULL) gives 134796800. (making fprintf(stderr,"%d",arrowBOT);), i suppose it gives an integer..

miran
Member #2,407
June 2002

The return value of load_bitmap() is a BITMAP pointer. You're supposed to check if the pointer is NULL or not NULL. If it is NULL it means load_bitmap() failed. You are supposed to check that every time you call load_bitmap().

Why are you drawing your first sprite to screen when you have made a buffer to draw to?

Why do you call acquire_screen()?

--
sig used to be here

JMonteiro .
Member #7,296
May 2006

I've checked it, it doesn't return NULL.
As for the second question, it was supposed to write to the buffer, but due to some tests i forgot to change that before posting. But it's buffer and it's not working.. :\

I've done the acquire_screen coz it was recommended in one post i saw, initialy it wasn't there.

miran
Member #2,407
June 2002

I edited my last post while you were typing. To reiterate: you must check that every bitmap loaded OK. If you get one wrong (because of wrong path, or mismatching filename case, or whatever), your code will crash. I also added a question about calling acquire_screen(). EDIT: hehe...

--
sig used to be here

JMonteiro .
Member #7,296
May 2006

Thanks man, i missed one bitmap when i changed the folder of my sources :) ..

Thank you so much for helping me get there ;)

Go to: