Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A4] What can make load_bitmap return a NULL pointer

This thread is locked; no one can reply to it. rss feed Print
[A4] What can make load_bitmap return a NULL pointer
larienna
Member #3,185
January 2003
avatar

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
avatar

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
avatar

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
avatar

Mark Oates
Member #1,146
March 2001
avatar

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()`)
- The image addon has not been initialized ( al_init_image_addon()).
- Your paths are not aligned... meaning that whatever the path is where you are running your program, it's not able to find the image relative to that. (you might start by putting the image in the same place as the program executable, and run the program from within the same path, and see if that works.)

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

BitCruncher
Member #11,279
August 2009
avatar

@Mark, it's Allegro 4.

Mark Oates
Member #1,146
March 2001
avatar

>:( DANGIT

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

BitCruncher
Member #11,279
August 2009
avatar

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
avatar

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
avatar

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.
Another option is to use the al_trace function, which prints a message to the Allegro log. The log can be viewed using the al_get_allegro_log function and can be useful for debugging when running a program from the command line or in a non-graphical environment.

Hope it will help.
Thanks

larienna
Member #3,185
January 2003
avatar

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
avatar

larienna
Member #3,185
January 2003
avatar

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
avatar

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"

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

larienna
Member #3,185
January 2003
avatar

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

Go to: