al_install_system fails inside shared library

I've been writing a game engine for about six years now using Allegro as a back-end.

Lately I've been upgrading the most recent version to use the various newer versions of C++, Visual Studio, and Allegro 5 seen here.

I've been doing some internal testing by outputting a compiled library and then having simple sample games using said output.

However, for some reason, the call al_install_system(ALLEGRO_VERSION_INT, std::atexit) returns false inside the function a2de_init() (Engine/a2de_base.cpp) when it is called from any of the sample games but not from the testing project for the library.

The documentation says nothing about what could cause the failure and only states: "Don't call it inside a shared library unless you know what you are doing." This is not helpful. Why does it fail? Why shouldn't it be called inside a shared library? What must I know to do this correctly?


Not sure what the problem might be, but aren't you supposed to use AND instead of OR here?

bool result = system_init_result || image_init_result ||
        primitives_init_result || font_init_result || ttf_init_result ||
        install_audio_result || acodec_init_result ||
        native_dialog_init_result || install_keyboard_result ||
        install_mouse_result || install_joystick_result;

And you shouldn't need to call any of the al_uninstall* functions, Allegro uses atexit to have them called automatically.

There is some info about this here:
The problem could be mismatched Allegro versions. And I'm guessing that the data structure that atexit uses to store function pointers when called from a shared library will not be seen by the C runtime shutdown code in the executable, because they are using different instances of the C runtime. But maybe that's why you are calling the al_uninstall* functions manually.


You're right! Fixed. :)

Frustratingly enough (not the funny kind of frustrating), a previously-created sample game works just fine and their main functions, Property Sheets, and Property Managers are exactly the same...

Anyway, I've "fixed" the problem by calling al_install_system(ALLEGRO_INT, std::atexit) just prior to the sample game's call to a2de::a2de_init(). It returns true when called from the game binary. Since the system is already installed a2de_init()'s version always returns true.

An actual fix would be nice. More descriptive errors or documentation explaining why the system was not installed correctly would be great.


Did you try doing what it says in the yellow box here? Allegro doesn't need the atexit pointer anyway, since you call the shutdown functions yourself.


Passing a nullptr atexit pointer to al_install_system still returns false for the newer project.

Edgar Reynaldo

Are you sure your library and your game are using the same versions of allegro? That is the first thing that comes to mind when al_init fails.

Also, something to note about using al_install_system inside a dll is that the dll has its own entry and exit point separate from main's entry and exit point. If al_uninstall_system is running inside the dll's exit function it can cause problems with the main exit function, causing things to be destroyed twice. I've run into that problem before.


Yep, that was it.

The engine test project was using the dynamic versions of the Allegro library, but the actual Library project that outputs the static library for others to use was using the Monolithic version. Since each test game was using the dynamic versions of Allegro, there was a version mis-match.

Thanks guys.

Brooklyn said:

I've been writing a game engine for about six years now using Allegro as a back-end.

This and your avatar remind me of the Charred Dirt project (R.I.P. forum) with ShadowFang. You know him?


This and your avatar remind me of the Charred Dirt project (R.I.P. forum) with ShadowFang. You know him?


Thread #616333. Printed from