SDL_PushEvent() is documented to return 0 on success. In fact, as
a simple wrapper for the all-purpose SDL_PeepEvents(…,SDL_ADDEVENT,…),
SDL_PushEvent() returns 1 on success (for 1 event pushed); returns 0
or -1 if an error occured.
SDL_PeepEvents() will return 0 if (! SDL_EventQ.active), which
seems like a minor bug – shouldn’t it return -1?
Still, a full-queue failure during a multi-event SDL_ADDEVENT call will
return something less than the numevents added (down to 0, but never -1).
So, really, SDL_PushEvent() returns 0 or -1 on a failure (0 meaning
the queue is full, -1 meaning something else went wrong), and 1 on
success. SDL_PeepEvents() returns -1 if something bad happened, the
number of events added (maybe less than numevents) when adding events,
and the number of events stored in events in the peek/get cases.
Finally, the events == NULL case in SDL_PeepEvents() should probably
return an error… (Right now, if events == NULL it does a single
event PEEK). I won’t touch that, though.
Both patches are against today’s CVS.
Here’s a simple patch for header-file doc:
Index: include/SDL_events.h===================================================================
RCS file: /home/slouken/libsdl.org/cvs/SDL12/include/SDL_events.h,v
retrieving revision 1.3
diff -u -b -r1.3 SDL_events.h
— include/SDL_events.h 2001/12/14 12:37:47 1.3
+++ include/SDL_events.h 2002/01/21 07:58:11
@@ -274,8 +274,8 @@
extern DECLSPEC int SDL_WaitEvent(SDL_Event *event);
/* Add an event to the event queue.
- This function returns 0, or -1 if the event couldn’t be added to
- the event queue. If the event queue is full, this function fails.
- This function returns 0 if the event queue was full, or -1
- if there was some other error. Returns 1 on success.
*/
extern DECLSPEC int SDL_PushEvent(SDL_Event *event);
And a simple patch for SDL_PeepEvents() if I’m right about returning
-1 on error.
Index: src/events/SDL_events.c
RCS file: /home/slouken/libsdl.org/cvs/SDL12/src/events/SDL_events.c,v
retrieving revision 1.3
diff -u -b -r1.3 SDL_events.c
— src/events/SDL_events.c 2001/12/14 12:38:13 1.3
+++ src/events/SDL_events.c 2002/01/21 07:50:41
@@ -301,7 +301,7 @@
/* Don't look after we've quit */
if ( ! SDL_EventQ.active ) {
-
return(0);
-
return(-1); } /* Lock the event queue */ used = 0;
Hhm… that’s probably a lot more text than this problem deserves.
Anyway, thanks for making such a spiffy toolkit open source!
-Pat
Pat Tullmann @Patrick_Tullmann
If Gates got a dime each time Windows crashed… Oh, nevermind…