Ive had trouble with this function since i first started using allegro 5 (a month ago ).
It seems that al_load_bitmap refuses to load a bitmap for me, i had gotten it to work for a while but then after i changed a couple lines somewhere it stopped,
heres my code
lines 69-71 are where it crashes
as a side note i double checked the spelling and the image file is in fact next to the .exe, Ive also attached the two image files.
Throw a fprintf in Game::init to make sure Allegro is being initialized before any bitmaps are loaded.
It could also be a path issue. al_filename_exists() will return true if the file is where it should be.
If Allegro isn't being initialized first I'd try changing Object Billy(true); to Object* Billy = new Object(true); and see if that works.
Make sure your game is being run from the same directory that it is in, otherwise relative paths will not work correctly.
After following your guys's advice i found it must be a path issue, allegro is initialized judging by the al_is_system_installed() function i added right before the al_load_bitmap. It must then be a path error which i cant grasp why, the file is named how it should and is right next to the .exe. the only modifications ive made to the program is now Object::Object(bool player) is as follows.
Object::Object(bool player) { if (player) { x = (SCREEN_W - OBJECTD)/2; y = (SCREEN_H - OBJECTD)/2; if (al_is_system_installed()) printf("allegro is installed\n");// true if (!al_filename_exists("playerball.bmp")) printf("it doesnt exist\n");// the file does not exist bitmap = al_load_bitmap("playerball.bmp"); if (bitmap == NULL) printf("erroer loding bitmap\n");// the pointer is null al_convert_mask_to_alpha(bitmap,al_map_rgb(255,255,255)); } }
not much changed (nothing functionally at least)
EDIT::Found the problem, was in fact a Path problem but not my fault,
my IDE code::blocks which i was running my program from, uses the project folder to look for resources and files, not the debug folder that holds the .exe where most would assume. The program runs when launched normally but will only function when launched from the IDE if the resources are in the main project folder!
You can fix this by setting the execution working directory of each build type of your project. Go to Project->Properties->Build Targets and set that to the directory where your program is built. You can see this by looking slightly up to the Output Filename textbox :
{"name":"604019","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/5\/c5d1dbcc351316d031ee7874dec1ebaf.png","w":702,"h":483,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/5\/c5d1dbcc351316d031ee7874dec1ebaf"}