Added an arbitrary limit to the number of queued events so it doesn't grow unbounded.
authorSam Lantinga
Tue, 11 Jun 2013 08:37:03 -0700
changeset 73061516fe08e6ec
parent 7305 d918643aee17
child 7307 5d6b7b9432d3
Added an arbitrary limit to the number of queued events so it doesn't grow unbounded.
src/events/SDL_events.c
     1.1 --- a/src/events/SDL_events.c	Tue Jun 11 08:32:55 2013 -0700
     1.2 +++ b/src/events/SDL_events.c	Tue Jun 11 08:37:03 2013 -0700
     1.3 @@ -33,6 +33,9 @@
     1.4  #endif
     1.5  #include "../video/SDL_sysvideo.h"
     1.6  
     1.7 +/* An arbitrary limit so we don't have unbounded growth */
     1.8 +#define SDL_MAX_QUEUED_EVENTS   65535
     1.9 +
    1.10  /* Public data -- the event filter */
    1.11  SDL_EventFilter SDL_EventOK = NULL;
    1.12  void *SDL_EventOKParam;
    1.13 @@ -71,6 +74,7 @@
    1.14  {
    1.15      SDL_mutex *lock;
    1.16      volatile SDL_bool active;
    1.17 +    volatile int count;
    1.18      SDL_EventEntry *head;
    1.19      SDL_EventEntry *tail;
    1.20      SDL_EventEntry *free;
    1.21 @@ -128,6 +132,7 @@
    1.22          SDL_free(wmmsg);
    1.23          wmmsg = next;
    1.24      }
    1.25 +    SDL_EventQ.count = 0;
    1.26      SDL_EventQ.head = NULL;
    1.27      SDL_EventQ.tail = NULL;
    1.28      SDL_EventQ.free = NULL;
    1.29 @@ -193,6 +198,11 @@
    1.30  {
    1.31      SDL_EventEntry *entry;
    1.32  
    1.33 +    if (SDL_EventQ.count >= SDL_MAX_QUEUED_EVENTS) {
    1.34 +        SDL_SetError("Event queue is full (%d events)", SDL_EventQ.count);
    1.35 +        return 0;
    1.36 +    }
    1.37 +
    1.38      if (SDL_EventQ.free == NULL) {
    1.39          entry = (SDL_EventEntry *)SDL_malloc(sizeof(*entry));
    1.40          if (!entry) {
    1.41 @@ -221,6 +231,7 @@
    1.42          entry->prev = NULL;
    1.43          entry->next = NULL;
    1.44      }
    1.45 +    ++SDL_EventQ.count;
    1.46  
    1.47      return 1;
    1.48  }
    1.49 @@ -247,6 +258,8 @@
    1.50  
    1.51      entry->next = SDL_EventQ.free;
    1.52      SDL_EventQ.free = entry;
    1.53 +    SDL_assert(SDL_EventQ.count > 0);
    1.54 +    --SDL_EventQ.count;
    1.55  }
    1.56  
    1.57  /* Lock the event queue, take a peep at it, and unlock it */