SDL_GetGamepads() follows the SDL_GetStringRule

This commit is contained in:
Sam Lantinga
2024-07-18 17:04:57 -07:00
parent 4961af4569
commit 5ce0aacaa4
3 changed files with 10 additions and 9 deletions

View File

@@ -468,17 +468,18 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasGamepad(void);
/** /**
* Get a list of currently connected gamepads. * Get a list of currently connected gamepads.
* *
* \param count a pointer filled in with the number of gamepads returned. * The returned array follows the SDL_GetStringRule, and will be automatically freed later.
* \returns a 0 terminated array of joystick instance IDs which should be *
* freed with SDL_free(), or NULL on failure; call SDL_GetError() for * \param count a pointer filled in with the number of gamepads returned, may be NULL.
* more details. * \returns a 0 terminated array of joystick instance IDs or NULL on failure; call SDL_GetError() for
* more information.
* *
* \since This function is available since SDL 3.0.0. * \since This function is available since SDL 3.0.0.
* *
* \sa SDL_HasGamepad * \sa SDL_HasGamepad
* \sa SDL_OpenGamepad * \sa SDL_OpenGamepad
*/ */
extern SDL_DECLSPEC SDL_JoystickID * SDLCALL SDL_GetGamepads(int *count); extern SDL_DECLSPEC const SDL_JoystickID * SDLCALL SDL_GetGamepads(int *count);
/** /**
* Check if the given joystick is supported by the gamepad interface. * Check if the given joystick is supported by the gamepad interface.

View File

@@ -317,7 +317,7 @@ SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadTypeForID,(SDL_JoystickID a),(a),r
SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadTypeFromString,(const char *a),(a),return) SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadTypeFromString,(const char *a),(a),return)
SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadVendor,(SDL_Gamepad *a),(a),return) SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadVendor,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadVendorForID,(SDL_JoystickID a),(a),return) SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadVendorForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickID*,SDL_GetGamepads,(int *a),(a),return) SDL_DYNAPI_PROC(const SDL_JoystickID*,SDL_GetGamepads,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_MouseButtonFlags,SDL_GetGlobalMouseState,(float *a, float *b),(a,b),return) SDL_DYNAPI_PROC(SDL_MouseButtonFlags,SDL_GetGlobalMouseState,(float *a, float *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetGlobalProperties,(void),(),return) SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetGlobalProperties,(void),(),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetGrabbedWindow,(void),(),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_GetGrabbedWindow,(void),(),return)

View File

@@ -2396,11 +2396,11 @@ SDL_bool SDL_HasGamepad(void)
return SDL_FALSE; return SDL_FALSE;
} }
SDL_JoystickID *SDL_GetGamepads(int *count) const SDL_JoystickID *SDL_GetGamepads(int *count)
{ {
int num_joysticks = 0; int num_joysticks = 0;
int num_gamepads = 0; int num_gamepads = 0;
SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks); SDL_JoystickID *joysticks = SDL_ClaimEventMemory(SDL_GetJoysticks(&num_joysticks));
if (joysticks) { if (joysticks) {
int i; int i;
for (i = num_joysticks - 1; i >= 0; --i) { for (i = num_joysticks - 1; i >= 0; --i) {
@@ -2414,7 +2414,7 @@ SDL_JoystickID *SDL_GetGamepads(int *count)
if (count) { if (count) {
*count = num_gamepads; *count = num_gamepads;
} }
return joysticks; return SDL_FreeLater(joysticks);
} }
const char *SDL_GetGamepadNameForID(SDL_JoystickID instance_id) const char *SDL_GetGamepadNameForID(SDL_JoystickID instance_id)