diff --git a/docs/README-migration.md b/docs/README-migration.md index f5b00db10..0089142f1 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -338,6 +338,8 @@ SDL_QUERY, SDL_IGNORE, SDL_ENABLE, and SDL_DISABLE have been removed. You can us SDL_AddEventWatch() now returns -1 if it fails because it ran out of memory and couldn't add the event watch callback. +SDL_RegisterEvents() now returns 0 if it couldn't allocate any user events. + The following symbols have been renamed: * SDL_APP_DIDENTERBACKGROUND => SDL_EVENT_DID_ENTER_BACKGROUND * SDL_APP_DIDENTERFOREGROUND => SDL_EVENT_DID_ENTER_FOREGROUND diff --git a/include/SDL3/SDL_events.h b/include/SDL3/SDL_events.h index 80709f9ec..4c30950c2 100644 --- a/include/SDL3/SDL_events.h +++ b/include/SDL3/SDL_events.h @@ -1199,15 +1199,8 @@ extern DECLSPEC SDL_bool SDLCALL SDL_EventEnabled(Uint32 type); * Allocate a set of user-defined events, and return the beginning event * number for that set of events. * - * Calling this function with `numevents` <= 0 is an error and will return - * (Uint32)-1. - * - * Note, (Uint32)-1 means the maximum unsigned 32-bit integer value (or - * 0xFFFFFFFF), but is clearer to write. - * * \param numevents the number of events to be allocated - * \returns the beginning event number, or (Uint32)-1 if there are not enough - * user-defined events left. + * \returns the beginning event number, or 0 if numevents is invalid or if there are not enough user-defined events left. * * \since This function is available since SDL 3.0.0. * diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index baaff2c99..c8cf8afb5 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -1447,13 +1447,11 @@ SDL_bool SDL_EventEnabled(Uint32 type) Uint32 SDL_RegisterEvents(int numevents) { - Uint32 event_base; + Uint32 event_base = 0; if ((numevents > 0) && (SDL_userevents + numevents <= SDL_EVENT_LAST)) { event_base = SDL_userevents; SDL_userevents += numevents; - } else { - event_base = (Uint32)-1; } return event_base; } diff --git a/test/testmessage.c b/test/testmessage.c index 056a1d5ea..2b8e39439 100644 --- a/test/testmessage.c +++ b/test/testmessage.c @@ -182,7 +182,7 @@ int main(int argc, char *argv[]) { int status = 0; SDL_Event event; - intptr_t eventNumber = SDL_RegisterEvents(1); + Uint32 eventNumber = SDL_RegisterEvents(1); SDL_Thread *thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void *)eventNumber); while (SDL_WaitEvent(&event)) {