Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index bca5375..75362d5 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -287,52 +287,48 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
} else {
SDL_EventEntry *entry, *next;
SDL_SysWMEntry *wmmsg, *wmmsg_next;
- SDL_Event tmpevent;
Uint32 type;
- /* If 'events' is NULL, just see if they exist */
- if (events == NULL) {
- action = SDL_PEEKEVENT;
- numevents = 1;
- events = &tmpevent;
- }
-
- /* Clean out any used wmmsg data
- FIXME: Do we want to retain the data for some period of time?
- */
- for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
- wmmsg_next = wmmsg->next;
- wmmsg->next = SDL_EventQ.wmmsg_free;
- SDL_EventQ.wmmsg_free = wmmsg;
+ if (action == SDL_GETEVENT) {
+ /* Clean out any used wmmsg data
+ FIXME: Do we want to retain the data for some period of time?
+ */
+ for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
+ wmmsg_next = wmmsg->next;
+ wmmsg->next = SDL_EventQ.wmmsg_free;
+ SDL_EventQ.wmmsg_free = wmmsg;
+ }
+ SDL_EventQ.wmmsg_used = NULL;
}
- SDL_EventQ.wmmsg_used = NULL;
- for (entry = SDL_EventQ.head; entry && used < numevents; entry = next) {
+ for (entry = SDL_EventQ.head; entry && (!events || used < numevents); entry = next) {
next = entry->next;
type = entry->event.type;
if (minType <= type && type <= maxType) {
- events[used] = entry->event;
- if (entry->event.type == SDL_SYSWMEVENT) {
- /* We need to copy the wmmsg somewhere safe.
- For now we'll guarantee it's valid at least until
- the next call to SDL_PeepEvents()
- */
- if (SDL_EventQ.wmmsg_free) {
- wmmsg = SDL_EventQ.wmmsg_free;
- SDL_EventQ.wmmsg_free = wmmsg->next;
- } else {
- wmmsg = (SDL_SysWMEntry *)SDL_malloc(sizeof(*wmmsg));
+ if (events) {
+ events[used] = entry->event;
+ if (entry->event.type == SDL_SYSWMEVENT) {
+ /* We need to copy the wmmsg somewhere safe.
+ For now we'll guarantee it's valid at least until
+ the next call to SDL_PeepEvents()
+ */
+ if (SDL_EventQ.wmmsg_free) {
+ wmmsg = SDL_EventQ.wmmsg_free;
+ SDL_EventQ.wmmsg_free = wmmsg->next;
+ } else {
+ wmmsg = (SDL_SysWMEntry *)SDL_malloc(sizeof(*wmmsg));
+ }
+ wmmsg->msg = *entry->event.syswm.msg;
+ wmmsg->next = SDL_EventQ.wmmsg_used;
+ SDL_EventQ.wmmsg_used = wmmsg;
+ events[used].syswm.msg = &wmmsg->msg;
}
- wmmsg->msg = *entry->event.syswm.msg;
- wmmsg->next = SDL_EventQ.wmmsg_used;
- SDL_EventQ.wmmsg_used = wmmsg;
- events[used].syswm.msg = &wmmsg->msg;
- }
- ++used;
- if (action == SDL_GETEVENT) {
- SDL_CutEvent(entry);
+ if (action == SDL_GETEVENT) {
+ SDL_CutEvent(entry);
+ }
}
+ ++used;
}
}
}