draw_sprite and crash!
Fire Wolf

Hey, last time I programmed something was over a year ago; I dont recall having too much of a problem.

When I draw_sprite from a file, this case "small.bmp", and I execute the .exe it crashes.

If I comment out draw_sprite( buffer, Newgame, 200, 200); it works fine...

Whats the problem??

1#define ALLEGRO_STATICLINK
2 
3#include <allegro.h>
4#include "CMenu.h"
5 
6 
7 
8BITMAP *buffer;
9 
10 
11//Menu buttons
12 
13BITMAP *Newgame;
14 
15 
16//Menus position
17//int NewgameX = 200;
18//int NewgameY = 150;
19 
20 
21 
22void CMenu::Menu()
23{
24 Newgame = load_bitmap( "small.bmp", NULL);
25 //menu system
26 while ( !key[KEY_ESC] ){
27 
28 
29
30 acquire_screen();
31
32 //makes everything black
33 //clear_to_color( screen, makecol( 0, 0, 0));
34
35 
36 draw_sprite( buffer, Newgame, 200, 200);
37
38 draw_sprite( screen, buffer, 0, 0);
39 release_screen();
40 
41
42 rest(50);
43 
44 }
45
46}
47 
48 
49int main(){
50
51 allegro_init();
52 install_keyboard();
53// install_mouse();
54 set_color_depth(16);
55 set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
56 
57 
58 buffer = create_bitmap( 800, 600);
59 
60// show_mouse(screen);
61
62 CMenu Menu;
63 Menu.Menu();
64
65 return 0;
66}
67 
68END_OF_MAIN();

Jakub Wasilewski

The standard advice: add checks to loading the bitmap, like:

  Newgame = load_bitmap(...);
  if (!Newgame)
  {
    allegro_message("Unable to load bitmap.");
  }

That way, you'll get some information on why your program is crashing if it is something wrong with the path.

As far as I can see, there are no other errors in your code (some bad practices, sure, but no errors per se), so there is a good chance your program just can't find/load the "small.bmp" file.

ixilom
Quote:

If I comment out draw_sprite( buffer, Newgame, 200, 200); it works fine...

That tells me the small.bmp didn't load correctly, do some error checking.
[Edit]
Beaten.

Fire Wolf

Whoa quick reply!

The strangest thing. There is acctually nothing wrong with the program...

When I exicute the .exe within Microsoft Visual C++ 6.0, it says it cant load the image. If I do it manually it works? How annoying?!

Richard Phipps

Then it sounds like a filepath issue..

Fire Wolf

Yes you were right, Changed my working directory. Thanks.

:)

Thread #591364. Printed from Allegro.cc