Ive added mouse functionality to my game and a strange thing happens, any time i move the mouse outside the game display window for more then a second or two the program exits. It doesn't crash, it just exits with a normal status zero. (obviously thats without grab_mouse) but when i use grab_mouse the same thing occurs if i have the mouse at any of the corners for the same length of time. I have no code which should allow this to occur... any help would be very appreciated.
You should show code and also try to produce a minimal example that reproduces this. Also, you ran it from a console and it is returning 0? On what conditions do you return from your program? Link the the allegro debug libraries and when your program runs, look at the allegro.log file created for clues.
And what versions are you using... compiler, allegro, and what os
Here is a minimal example that reproduces the effect:
in order to get the exit to happen just wiggle the cursor around your desktop both on and off of the display. i added the debug.h file but could find no log.
i am running windows 7 home premium sp 1 64 bit, allegro 5 (the most recent stable release), mingw gcc 4.8.1
Change this part of your code:
To this:
You have to check first what kind of event you have got from the queue and then process is.
At first glance it seems that when the mouse leaves window area the ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY is fired, and the values of that event match the ALLEGRO_KEY_ESCAPE condition you are checking for ( without the check for event type ).
And that makes your program exit, just like you wanted.
One thing to know is that allegro stores the event data in a "shared" data type. It shares space in the same structure for the different event types. So you ALWAYS want to check what type the event is when checking for the actual events, otherways odd things can and will happen.
Yup, That did it, thanks! And I'll be sure to remember that in the future!