- Online Community Forums » Allegro Development » Crashing program when attempt to draw a bitmap region.

This thread is locked; no one can reply to it. rss feed Print
Crashing program when attempt to draw a bitmap region.
Member #15,019
March 2013

Using Code::Blocks,MinGW 4.5.0 GNU-GCC compiler on Allegro 5.0.9
On my windows 7 laptop, when i attempt to draw a bitmap region to the screen such as:
... It will just crash the program.
I myself do not know any clue as to why it occurs, except the fact that i am attempting to run it on my own computer, and not my school computers. Is there any other variables that could've caused this issue? Perhaps the issue is that the school computers are running windows vista and I am not?
The link above is the code for the game i have that works just fine on the school computers.

Made a new link, should work now sorry about that, i tried to use this sites attachments =/

Member #7,827
October 2006

That link does not work. Attach the code to your post, perhaps...

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Member #15,020
March 2013

A couple of things to note:

  1. You should never use absolute paths when loading resources, for example, when you're loading the bitmap J:\\Final Project\\GalagaSprite.bmp. Use a path relative to the binary. Instead, if your executable is in J:\FinalProject, create a folder called J:\FinalProject\bitmaps, and put GalagaSprite.bmp in there. Then use al_load_bitmap("bitmaps/GalagaSprite.bmp"). Not all computers have the same drive letters, nor can you be certain that your program will be installed in the same directory on every computer. This, alone, could be the cause for your problem.

  2. A program doesn't "just crash". What type of error are you getting? If we know what type of error you're getting, that will make things easier to debug.

Allegro has been tried and testing very thoroughly, so it's highly unlikely this is an issue involving Allegro or the operating system specifically.

Hope that helps!

Edgar Reynaldo
Member #8,592
May 2007

ProjectV0.5 (his code on Pastebin)


107 GalagaSprite = al_load_bitmap("E:\\Final Project\\GalagaSprite.bmp"); 108 GalagaBackGround1 = al_load_bitmap("E:\\Final Project\\Galaga backgrounds\\Galaga Background1.png"); 109 GalagaBackGround2 = al_load_bitmap("E:\\Final Project\\Galaga backgrounds\\Galaga Background2.png"); 110 if (!GalagaSprite && !GalagaBackGround1 && !GalagaBackGround2) 111 { 112 GalagaSprite = al_load_bitmap("J:\\Final Project\\GalagaSprite.bmp"); 113 GalagaBackGround1 = al_load_bitmap("J:\\Final Project\\Galaga backgrounds\\Galaga Background1.png"); 114 GalagaBackGround2 = al_load_bitmap("J:\\Final Project\\Galaga backgrounds\\Galaga Background2.png"); 115 } 116 else 117 cout << "A Bitmap failed a load!" << endl;

Yes, atlasc1 is right - don't use absolute paths. And don't use windows path separators either, use a single forward slash like in Linux.

ALLEGRO_BITMAP* GalagaSprite = al_load_bitmap("Galaga Backgrounds/GalagaSprite.bmp");
if (!GalagaSprite) {cout << "failed to load GalagaSprite" << endl;}
// repeat for each bitmap to load.

And you would make sure that your exe is in the same folder as the Galaga Backgrounds folder, and that you have set the current working directory to that folder as well. See al_get_standard_path and al_change_directory for details. Use ALLEGRO_RESOURCES_PATH to get the path.

And one final note, al_draw_bitmap_region won't fail unless your pointer is null or you destroyed it and then tried to draw it again.

Member #14,001
February 2012

Given the boundary conditions you gave us, I also vote for a failure in loading the images, failre that you do not trap.

Alas, you are checking return values...but in the bitter case you fail to load you just print out to the console and go on...nah, it's not safe...program should terminate with an error message.

You may very well NOT have console window open in release mode, IIRC.

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

Go to: