Hi all,
I'm trying to create a CLI wrapper for allegro 5.2 using the latest nuget package so I can use allegro in c#. When I try to run my test console app, my app crashes on al_init(). When I say crash I mean the application just dies immediately with no exception or anything. Any Ideas?
.h
namespace AllegroSharp { public ref class Allegro { public: bool UseImageAddon; bool Initialize(); }; }
.cpp
#include "Allegro.h" #include "allegro5\allegro.h" #include "allegro5\allegro_image.h" bool AllegroSharp::Allegro::Initialize() { bool allegroOk = al_init(); // crashes here bool imageAddonOk = UseImageAddon ? al_init_image_addon() : true; return allegroOk && imageAddonOk; }
C#
EDIT: I'm starting to the think it has something to do with the entry point. I put the no entry point flag for my dll so i could link it. I figured allegro would provide the entry point when the user of the dll calls allegro init. I'm trying to compile it with a dllmain function in my dll but the linker can't seem to find it.
You generally never want to call al_init from a library (see its documentation), so at the very least you should try calling al_install_system instead.
I was trying that but it seemed to crash as well. I think I supplied nullptr for the second parameter. Is that correct or should I use something else?
EDIT: It worked, thanks.
Note: It is typically wrong to call al_init anywhere except the final game binary. In particular, do not call it inside a shared library unless you know what you're doing. In those cases, it is better to call al_install_system either with a NULL atexit_ptr, or with a pointer to atexit provided by the user of this shared library.
New news to me!