![]() |
|
[A4] What can make load_bitmap return a NULL pointer |
larienna
Member #3,185
January 2003
![]() |
I am trying to open some very small .bmp files I made in gimp, and when I try to open them, I get a null pointer. I thought that there could something wrong with my bmp format, maybe some have alpha channel, maybe some have the wrong color depth. Is there a way to get any debugging message from allegro? Else, what is the BMP format that must be respected for true color bitmaps. Enjoy! and have fun |
LennyLen
Member #5,313
December 2004
![]() |
I know (with about 99.99% certainty) that the 24-bit format that mspaint uses is supported, so you could use that to test to see if the format is the issue. If you're not on Windows, if you upload it, I can convert it for you.
|
BitCruncher
Member #11,279
August 2009
![]() |
Also, probably obvious, but make sure the library is initialized first before calling load_bitmap(); it will return NULL if this isn't the case.
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Export them from GIMP as 24 bit RGB .bmp files and they should work. Other considerations are the CWD at run time. Absolute vs relative paths, etc... 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 |
Mark Oates
Member #1,146
March 2001
![]() |
There are a few things that could be happening, but I agree with LennyLen that there's a 99.99% certainty that it isn't your bitmap. Usual errors are: - Allegro has not been initialized (`al_init()`) -- |
BitCruncher
Member #11,279
August 2009
![]() |
@Mark, it's Allegro 4.
|
Mark Oates
Member #1,146
March 2001
![]() |
-- |
BitCruncher
Member #11,279
August 2009
![]() |
It's a bizarre case and you probably aren't doing this, but I can remember a time when I was first getting starting that I tried to initialize a global bitmap pointer with load_bitmap() and this is a special (and totally not obvious) case of calling load_bitmap() before the library is initialized and will fail since any global evaluations occur before any main code is run.
|
larienna
Member #3,185
January 2003
![]() |
Thanks for the feedback. The code is on another computer, so I cannot check it immediately. I am pretty sure I initialized allegro. Maybe it is the path since it's using a path passed in command line argument. Maybe it needs to be modified before using. I am basically trying to make a tool take takes multiple small bitmaps and converge them into a single bitmap atlas similar to bitmap fonts. In GIMP, when I file->open, some files are marked as "RGB, 1 layer" while others are marked as "RGB-alpha, 1 layer". The bitmaps with alpha could be posing a problem, but if I remember my test results correctly, all files failed to open. Enjoy! and have fun |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
RGB only. alpha is not supported in 24 bit color depth .bmp .BMP files. 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 |
Gulshan Negi
Member #23,636
January 2023
|
Well, Yes Allegro has a number of functions that can be used for debugging. One common method is to use the al_show_native_message_box function, which displays a message box with a specified message, title, and set of buttons. This can be useful for displaying error messages or other debugging information to the user. Hope it will help. |
larienna
Member #3,185
January 2003
![]() |
I am super busy in recent months, so I did not have much time to review the code. I managed to push the code on gitlab: https://gitlab.com/larienna/glymmer/-/blob/dev/src/tool/glyphpacker.c Error should arrive at line 227 when load_bitmap returns a null pointer. On line 226 I open a specific file name for debugging purpose and it fails. The real bitmap loading is on line 240 where it fails too. In a nutshell, It tries to load files named in hexadecimal from 00.bmp to FF.bmp and copy the content into a new bitmap file that will be created. It seems I am redoing a more simple load_bitmap() tests directly in the main at line 298 and it fails too. Does allegro has internal error message I could display to know why load_bitmap() returns a null pointer? It would be useful to display it to the user. My next step is to try each file in my list manually and see which one does not return a null pointer. Then try to see what are the settings on those files since I suspect it's an unsupported BMP format. Enjoy! and have fun |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Just test your loading code first, then worry about the atlas. Use an absolute path in your loading code, to test issues with the path. Save in kolourpaint or something else to test different .bmp formats. 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 |
larienna
Member #3,185
January 2003
![]() |
I made some additional tests and it seems the file format was defective, but I cannot identify the problem. I would need a program that output file description to knows what differs. If I save the bitmap with GIMP in 24 bit mode, the file cannot be opened. If I reopen the file with mtPaint and re-save the file, The file can be opened by load_bitmap(). Again, not sure what Gimps attempt to do that mtPaint does not do. Enjoy! and have fun |
Dizzy Egg
Member #10,824
March 2009
![]() |
Is your Gimp version up to date? Also make sure when saving as a bmp from Gimp you select Advanced Options and check "Do not write colour space information"
---------------------------------------------------- |
larienna
Member #3,185
January 2003
![]() |
I installed recently Debian Bulleye, so yes, it is the latest version. I know about that color space option. From what I remember, I think I checked that option, because I know it could create issues. But I can take another look at it. Enjoy! and have fun |
|