So I've been messing around with A5 some more and the next thing I've decided to learn is how to properly use/define User Defined Events in Allegro. So I made a simple project just to learn the basics. And I have been experiencing nothing but problems for a few days now. So, I would be very grateful if someone could tell me why the following does not work as intended. Thanks in advanced.
Note: this is a smaller snippet of my code and hopefully I have included all the relevant code here.
Main.cpp
int main() { //all basic allegro stuff has been initialized at this point ALLEGRO_EVENT_QUEUE *event_queue = NULL; SubMenu_UserEvent::Instance(); //this is here to call the "SubMenu_UserEvent" ctor al_register_event_source(event_queue, &SubMenu_UserEvent::Instance()->Get_Source()); SubMenu_UserEvent::Instance()->TestEvent(); //fails. //. //. //.
Example.h
Example.cpp
Thanks,
It's because you're using the address of a temporary copy of your ALLEGRO_EVENT_SOURCE.
Try this :
ALLEGRO_EVENT_SOURCE& Get_Source() {return subMenu_event_source;}
Otherwise you're just registering a copy. Which won't work.
Specifically, this expression fails to give you the address of your event source :
&SubMenu_UserEvent::Instance()->Get_Source()
hahahaha...I can't believe I missed that. Three days of staring at this thing and I didn't catch that. I guess I just needed a fresh pair of eyes to look at it. Thanks a lot Edgar.