|
al_get_bitmap_height() sometimes return 0 on a loaded bitmap |
TeaRDoWN
Member #8,518
April 2007
|
I’m trying to resurrect a 7 year old project and have finally got it to compile and run. However I’ve encountered a very weird bug. About 50-66% of the launches al_get_bitmap_height() return the value 0 on a loaded png bitmap that is 20x20 pixels. This does not happen every time. Anyone encountered this? My guess is that there is some old junk in the code or something. I doubt it is a memory leak or accessing memory outside or arrays or such as the issue happens even if I load the bitmap and check the height just after initializing the Allegro graphic routines and creating the display. Not loading the image and then doing other allocations before checking height. Any suggestions? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
What version of Allegro are you running? Is it a dangling pointer? Show code. Minimal example please. Provide a debugging binary as well if possible. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
TeaRDoWN
Member #8,518
April 2007
|
5.0.10 I think. Not at my computer right now. The code is huge as it is a big project. However I’ve used the same version of Allegro to make other apps and not have the same problem. Just hoped someone would have encountered this before and what was the issue for them. The issue still happens if I load the bitmap and instantly afterwards check its height: I also tried this if it was something to do with trying to load too soon on execution: 1while (1)
2{
3 ALLEGRO_BITMAP *image = al_load_bitmap("ButtonFrame.png");
4 int a = al_get_bitmap_height(image);
5 if (a == 0)
6 al_destroy_bitmap(image);
7 else
8 break;
9}
However this did not solve anything. Ended up in a never ending loop so when it fails in doesn't become better when trying again, and again, and... |
MikiZX
Member #17,092
June 2019
|
Long shot idea, possibly you need to whitelist your game's folder/executable in your antivirus software? EDIT: Also, when the height is reported as 0 is the bitmap loaded in the memory (as in not NULL) and does it draw correctly? Does changing to a different bitmap give the same results? |
Audric
Member #907
January 2001
|
I would first check if image is NULL. If it is, then your issue has nothing to do with al_get_bitmap_height() Assuming the problem IS random, do you still have the issue if you put an absolute image path? ("c:\\myprojects\\mygame\\data\\ButtonFrame.png") ? If it makes it disappear for this image, it means that something (the initialization of a third-party lib?) is changing the current directory of your program for some time, then restoring it. The randomness would depend on how fast the different threads run. If you can't pinpoint such issue and solvie it, then you can't trust relative paths... In such case you can have to build absolute paths, using ALLEGRO_EXENAME_PATH + "/" + relativePath |
TeaRDoWN
Member #8,518
April 2007
|
Image is not null when I execute in debug and check the image pointer. It shows an address to memory. It does not matter if I load another image. Same result. Running another project work as intended so I don't think it is my environment. So it must be my project, not the environment or the asset(s) loaded. It was a big project I worked on 2012-2013 that I wanted to finish. There is a lot of "bad code" that I upgraded. While doing this it was crushing hundreds of bugs when using pointers to structs instead of cloning structs and such. I'm thinking if somewhere there is an array going bonkers or something but these normally do not act up making data corrupt until you start putting things out of range. I just tried to draw the 0 height sprite on screen and see what happens. The al_draw_bitmap() function did NOT fail...BUT nothing was drawn on screen. |
MikiZX
Member #17,092
June 2019
|
One thing you could try is to set al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); before creating your bitmaps and see if the issue repeats. I think this command would cause all bitmaps to be created in RAM and not on the GPU - so one thing would be excluded from possible reasons. Though I am a complete noob to Allegro5 so my understanding of things Allegro5 is likely off ... |
Edgar Reynaldo
Major Reynaldo
May 2007
|
5.0.10 is OLD. Upgrade to 5.2.5+, and then we can talk. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
TeaRDoWN
Member #8,518
April 2007
|
5.0.10 might be old sure but is the newest under Allegro.cc / Files / Binaries. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
allegro.cc hasn't been updated in years. liballeg.org is the home of allegro, not allegro.cc My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
TeaRDoWN
Member #8,518
April 2007
|
Thanks. Checked but could not (might be blind) find pre-compiled versions for MS Visual Studio. Anyone know where to find that? MikiZX: Using ALLEGRO_MEMORY_BITMAP instead of ALLEGRO_VIDEO_BITMAP did not help, getting same issue. Today I was able to run 10ish times before the issue occured. The frequency varies so much. After it happened once it now start to happen constantly. |
MiquelFire
Member #3,110
January 2003
|
For Visual Studio, use Nuget. There's two packages, one for Allegro itself, and one for the dependacies. --- |
TeaRDoWN
Member #8,518
April 2007
|
Sorry for asking but what is Nuget? |
MikiZX
Member #17,092
June 2019
|
https://wiki.allegro.cc/index.php?title=Windows,_Visual_Studio_2015_and_Nuget_Allegro_5 the part called 'Install the Allegro Package' or for more details: https://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio |
|