Make sure we don't stay in the windows event loop forever if there are lots of events coming in quickly.
authorSam Lantinga <slouken@libsdl.org>
Fri, 14 Feb 2014 11:39:58 -0800
changeset 8218cf153cc95173
parent 8217 13c461fb28c7
child 8219 49dbdbd657a9
Make sure we don't stay in the windows event loop forever if there are lots of events coming in quickly.
src/video/windows/SDL_windowsevents.c
     1.1 --- a/src/video/windows/SDL_windowsevents.c	Fri Feb 14 11:38:59 2014 -0800
     1.2 +++ b/src/video/windows/SDL_windowsevents.c	Fri Feb 14 11:39:58 2014 -0800
     1.3 @@ -25,6 +25,7 @@
     1.4  #include "SDL_windowsvideo.h"
     1.5  #include "SDL_windowsshape.h"
     1.6  #include "SDL_syswm.h"
     1.7 +#include "SDL_timer.h"
     1.8  #include "SDL_vkeys.h"
     1.9  #include "../../events/SDL_events_c.h"
    1.10  #include "../../events/SDL_touch_c.h"
    1.11 @@ -537,10 +538,10 @@
    1.12  
    1.13              /* Detect relevant keyboard shortcuts */
    1.14              if (keyboardState[SDL_SCANCODE_LALT] == SDL_PRESSED || keyboardState[SDL_SCANCODE_RALT] == SDL_PRESSED ) {
    1.15 -	            /* ALT+F4: Close window */
    1.16 -	            if (code == SDL_SCANCODE_F4) {
    1.17 -		            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
    1.18 -	            }
    1.19 +                /* ALT+F4: Close window */
    1.20 +                if (code == SDL_SCANCODE_F4) {
    1.21 +                    SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
    1.22 +                }
    1.23              }
    1.24  
    1.25              if ( code != SDL_SCANCODE_UNKNOWN ) {
    1.26 @@ -860,10 +861,17 @@
    1.27  {
    1.28      const Uint8 *keystate;
    1.29      MSG msg;
    1.30 +    DWORD start_ticks = GetTickCount();
    1.31 +
    1.32      while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
    1.33          /* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
    1.34          TranslateMessage(&msg);
    1.35 -        DispatchMessage(&msg);
    1.36 +        DispatchMessage( &msg );
    1.37 +
    1.38 +        /* Make sure we don't busy loop here forever if there are lots of events coming in */
    1.39 +        if (SDL_TICKS_PASSED(msg.time, start_ticks)) {
    1.40 +            break;
    1.41 +        }
    1.42      }
    1.43  
    1.44      /* Windows loses a shift KEYUP event when you have both pressed at once and let go of one.