diff --git a/include/SDL3/SDL_gamepad.h b/include/SDL3/SDL_gamepad.h index 3313bd6f7e..36ad8e1c77 100644 --- a/include/SDL3/SDL_gamepad.h +++ b/include/SDL3/SDL_gamepad.h @@ -1023,15 +1023,17 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void); /** * Get the SDL joystick layer bindings for a gamepad. * + * This returns temporary memory which will be automatically freed later, and + * can be claimed with SDL_ClaimTemporaryMemory(). + * * \param gamepad a gamepad. * \param count a pointer filled in with the number of bindings returned. - * \returns a NULL terminated array of pointers to bindings which should be - * freed with SDL_free(), or NULL on failure; call SDL_GetError() for - * more details. + * \returns a NULL terminated array of pointers to bindings or NULL on failure; call SDL_GetError() for + * more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC SDL_GamepadBinding ** SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count); +extern SDL_DECLSPEC const SDL_GamepadBinding * const * SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count); /** * Manually pump gamepad updates if not using the loop. diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index e3d288403d..0eeb706abf 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -276,7 +276,7 @@ SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForAxis,(SDL_Gamepad SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return) SDL_DYNAPI_PROC(Sint16,SDL_GetGamepadAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return) SDL_DYNAPI_PROC(SDL_GamepadAxis,SDL_GetGamepadAxisFromString,(const char *a),(a),return) -SDL_DYNAPI_PROC(SDL_GamepadBinding**,SDL_GetGamepadBindings,(SDL_Gamepad *a, int *b),(a,b),return) +SDL_DYNAPI_PROC(const SDL_GamepadBinding* const*,SDL_GetGamepadBindings,(SDL_Gamepad *a, int *b),(a,b),return) SDL_DYNAPI_PROC(Uint8,SDL_GetGamepadButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return) SDL_DYNAPI_PROC(SDL_GamepadButton,SDL_GetGamepadButtonFromString,(const char *a),(a),return) SDL_DYNAPI_PROC(SDL_GamepadButtonLabel,SDL_GetGamepadButtonLabel,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return) diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c index 5d023396aa..b2576dc26d 100644 --- a/src/joystick/SDL_gamepad.c +++ b/src/joystick/SDL_gamepad.c @@ -3543,7 +3543,7 @@ SDL_Gamepad *SDL_GetGamepadFromPlayerIndex(int player_index) /* * Get the SDL joystick layer bindings for this gamepad */ -SDL_GamepadBinding **SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count) +const SDL_GamepadBinding * const*SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count) { SDL_GamepadBinding **bindings = NULL; @@ -3574,7 +3574,7 @@ SDL_GamepadBinding **SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count) } SDL_UnlockJoysticks(); - return bindings; + return SDL_FreeLater(bindings); } int SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)