Hi,
I'm currently debugging my multi monitor code for Eagle and every time I shut down Eagle after creating a EagleGraphicsContext( a window ) it hangs in Allegro5WindowManager::Destroy here :
https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/backends/Allegro5/Allegro5WindowManager.cpp#L304-L314
The Allegro5WindowManager process is alive and waiting on an event (in this case, EAGLE_EVENT_WM_DESTROY :
https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/backends/Allegro5/Allegro5WindowManager.cpp#L37
which should have been sent by the above code, but that message never arrives. Can anyone help me debug this and figure out why my event is missing?
Edgar
This probably doesn't really help, but the first thing I thought of was if the Allegro event system is somehow tied to the window/display, and you destroy that, perhaps the event pipeline would get lost. Just a guess, and it's probably not true if the event queues don't require a display to function.
ALLEGRO_EVENT_QUEUE and ALLEGRO_EVENT_SOURCE are both completely separate from an ALLEGRO_DISPLAY.
I don't know what's wrong. If I set a breakpoint in WM::Destroy I see the event get emitted! It is just never received by the A5WindowManagerProcess. I only unregister the event source once, on destruction later on in WM::Destroy here :
https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/backends/Allegro5/Allegro5WindowManager.cpp#L316-L321
I create and initialize and register them here :
https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/backends/Allegro5/Allegro5WindowManager.cpp#L264-L277
Those are the only places I create or destroy or register or unregister the window_event_source. This is everything grep returns that has anything to do with the window event source :
c:\ctwoplus\progcode\Eagle5GUI_GIT_BitBucket\src>grep -r -E -I -n "window_event_source" .*.*
.\backends/Allegro5/Allegro5WindowManager.cpp:42: if (ev.any.source == &(a5man->window_event_source)) {
.\backends/Allegro5/Allegro5WindowManager.cpp:130: ev.any.source = &window_event_source;
.\backends/Allegro5/Allegro5WindowManager.cpp:133: al_emit_user_event(&window_event_source , &ev , 0);
.\backends/Allegro5/Allegro5WindowManager.cpp:150: if (ev.any.source == &window_event_source) {
.\backends/Allegro5/Allegro5WindowManager.cpp:245: window_event_source(),
.\backends/Allegro5/Allegro5WindowManager.cpp:264: al_init_user_event_source(&window_event_source);
.\backends/Allegro5/Allegro5WindowManager.cpp:277: al_register_event_source(window_queue , &window_event_source);
.\backends/Allegro5/Allegro5WindowManager.cpp:307: ev.any.source = &window_event_source;
.\backends/Allegro5/Allegro5WindowManager.cpp:311: al_emit_user_event(&window_event_source , &ev , 0);
.\backends/Allegro5/Allegro5WindowManager.cpp:317: al_unregister_event_source(window_queue , &window_event_source);
.\backends/Allegro5/Allegro5WindowManager.cpp:318: al_destroy_user_event_source(&window_event_source);
c:\ctwoplus\progcode\Eagle5GUI_GIT_BitBucket\src>
This is maybe a bit of a hack, but if you comment out the unregister/destroy event source business does the event arrive? I'm just curious if that would help to track down the cause.. I'm just guessing mind you. If I can find any ambition I could try to get it installed and test it myself later on this weekend or something. Have you tried on other machines? Sometimes that can change things too. I'd be testing in Linux, assuming Eagle supports that.
Tested on Windows and Linux, that's all I have access to. Does the exact same thing, whether in Windows 10, or OpenSUSE 44.
It currently builds with C::B and MinGW/GCC and needs allegro installed either in the root directory in a folder called allegro or in usr/local/lib, or in your compiler directory (eww).
This is probably paranoid, but I suspect it's a heisenbug or memory corruption or something. I tried to rule out race conditions by creating a EagleLogGuard, which seems to be working fine to serialize log output.
EDIT
There is some hanky panky going on in my code somewhere....
If I add in this line :
EAGLE_ASSERT(al_is_event_source_registered(window_queue , &(a5man->window_event_source)));
It passes the assert when closing the window, but then immediately fails the assert. Something is "un-registering" my window_event_source from the window queue.
There's also something fishy here in my log :
EAGLE INFO : Allegro5WindowManager::AddDisplay - adding ALLEGRO_DISPLAY* 0420c2e0 . ... EAGLE INFO : A5WindowManagerProcess : Closing display 0420a0b0
I only ever created one display! Why is their address different?
This is getting interesting!
I found the issue. 
Super facepalm here.
Look at the highlighted lines :
https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/backends/Allegro5/Allegro5WindowManager.cpp#L56-L66
The event I was sending for EAGLE_EVENT_WM_CLOSE_WINDOW was a user event not a display event, but I was accessing ev.display.source, which was garbage (or in this case happened to be the same as &window_event_source, which un-registered it from the queue and prevented the EAGLE_EVENT_WM_DESTROY message to be received. This has taken me weeks to find.
Thanks for updating us on that! Just one of those bugs...
Maybe we should add a function:
ALLEGRO_DISPLAY_EVENT *al_get_display_event(ALLEGRO_EVENT *event);
And it would return NULL if the event is not a display event, and otherwise the display event. And the same for all the other event types. And we could deprecate direct access to the ALLEGRO_EVENT structur and you would instead use:
al_get_display_event_source(al_get_display_event(ev))
Which would crash if the event is the wrong type, and so you would have immediately found this bug. Direct struct access of a union in C++ is bad
Glad you got it figured out!
EDIT
I think all the problems are solved (with window destruction at least). Test program now successfully creates and destroys windows on command.
Drawing is another matter.
Build is stable and fixed if you want to try things out bammccaig.
git clone https://github.com/EdgarReynaldo/EagleGUI.git
EDIT2
Drawing text is still messed up. Only the most recently loaded font shows up when drawing to multiple windows.
EDIT3
A clean example of multiple windows works fine when using strictly allegro. Text gets drawn normally.
https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/tests/AllegroMultiWin.hpp