Allegro 5.2.x and Raspberry Pi - failed to create display


In my Rasperry Pi project, I've just updated from Allegro version 5.1.13 to 5.2.2. Now however, whenever I call al_create_display() it always returns null. I also noticed that al_get_num_display_modes() returns 0, not 1 as in version 5.1.13.

It also fails for allegro 5.2.1. When I revert to 5.1.13, and rebuild my code, it magically works again (i.e. al_create_display() returns a non-null value and my program can continue ok with it's graphics output), so I reckon it's a reasonable assumption that it's something to do with the Allegro version and not my program or the OS?

I have tried even with a very simple program (al_init() followed by al_create_display()) and it still doesn't work.

I'm using the very latest raspian image from the Raspberry Pi website.

Anyone else have this problem?

Thanks in advance,

Chris Katko

Check to make sure the LIBRARY, DLL/SO, and include files are all the same version. It might be using a library in your user folder that you don't realize. Such as the symbolic links for "Allegro" link to "Allegro 5.1.x", which is why your old version still works.

I ran into this issue when trying DAllegro, and I think I've hit it before upgrading Allegro minor versions.



Thanks for the response. I don't think this is my issue, however - I am working with a completely fresh install (new SD card with latest raspbian, and allegro install), so no old versions of allegro files kicking about...

The only common files are my program source code, but it's just cpp, hpp and the Makefile, and again, I'm building from scratch.

As I said, I then installed and built with Allegro 5.1.13 and it works fine.


Edgar Reynaldo

Check to see if al_init() is failing. If it is, you've got a library mismatch most likely.


al_init() is ok (it's returning a non-zero value)

Edgar Reynaldo

What parameters are you passing to al_create_display? By default it creates a window. You may need to pass ALLEGRO_FULLSCREEN or ALLEGRO_FULLSCREEN_WINDOW in order to properly create a screen.


Code snippet attached. The output I get is...

Failed to create 1024 x 768 display

So al_get_monitor_info() fails, presumably because al_get_num_display_modes had returned zero?

1bool InitAllegro(void) { 2 if (!al_init()) Message->Print(FATAL, "Failed to initialize Allegro"); 3 al_init_font_addon(); 4 if (!al_init_primitives_addon()) Message->Print(FATAL, "Failed to initialize Allegro Primitives addon"); 5 if (!al_init_ttf_addon()) Message->Print(FATAL, "Failed to initialize Allegro TTF addon"); 6 if (!al_init_image_addon()) Message->Print(FATAL, "Failed to initialize Allegro Images addon"); 7 myprog_logo_f = al_open_memfile(myprog_logo_data, MYPROG_LOGO_LEN, "rb"); 8 if (!myprog_logo_f) Message->Print(FATAL, "Failed to load logo mem file"); 9 10 myprog_font_f = al_open_memfile(myprog_font_data, MYPROG_FONT_LEN, "rb"); 11 if (!myprog_font_f) Message->Print(FATAL, "Failed to load font mem file"); 12 13 myprog_font_size = 0; 14 15 // default width and height... 16 display_width = 1024; 17 display_height = 768; 18 19 ALLEGRO_MONITOR_INFO monitor; 20 Message->Print(DEBUG, "al_get_num_display_modes=%d", al_get_num_display_modes()); 21 if (al_get_monitor_info(0, &monitor)) { // find out current monitor resolution 22 display_width = monitor.x2 - monitor.x1; 23 display_height = monitor.y2 - monitor.y1; 24 Message->Print(NOTE, "Detected display monitor size %dx%d", display_width, display_height); 25 } 26 27 al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); 28 // al_set_new_display_flags(ALLEGRO_FULLSCREEN); 29 myprog_display = al_create_display((int)display_width, (int)display_height); 30 if (!myprog_display) Message->Print(FATAL, "Failed to create %d x %d display", display_width, display_height);

Chris Katko

Pretty sure you can't get monitor info until you create a display. It's a quirk of how all operating systems work. The display (a window handle) is how you communicate with all graphics related requests. (Unless you want to support two APIs, one using the display handle, and one using other system calls. IIRC.)

Maybe I'm wrong.

[edit] Yep, looks like I'm wrong.

How about trying this:

What does:

Detected display monitor size %dx%d


Try adding +1 to each of those width/height values.


It works fine with Allegro 5.1.13...and also if the get monitor info call fails it doesn't really matter - it then just tries to create a display with the default values (1024x768), but that fails all the time.

I've tried changing the default values to different numbers (including the actual size of the raspberry pi display given by tvservice) and it still doesn't work :(

I get none of these issues with allegro 5.1.13.

If I cahnage the above code to print the detected monitor size regardless of the return value, it says "Detected monitor size 0x0".

Adding +1 to the width and height when trying to create the display makes no difference


I just tried your code on my RaspberryPi, and everything worked fine.

There a few things to note. First, it doesn't matter what you pass to al_create_display on RaspberryPi, as it will ignore it and simply create a full-screen window with the current mode. There are no windowed displays on RaspberryPi (maybe one day).

Second, al_get_num_display_modes is hardcoded to return 1 on RaspberryPi (source). It's impossible for that backend to return 0.

It seems like you might have compiled Allegro in its regular Linux mode, did you follow the instructions here: ?.



So if al_get_num_display_modes is hard-coded to return 1, then something is seriously wrong! I'm 99.9% sure I built the allegro libraries correctly using the correct raspberrypi toolchain file for cmake, but I will try again from scratch; I've obviously messed up somewhere.

Thanks for your help. I'll let you know how I get on.

...all good now - reinstalled everything from scratch and it's now working. Not sure why I had problems before.

Thanks for your help - sorry to waste your time on a problem that didn't exist...

Thread #616797. Printed from