mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-06 03:18:13 +00:00
Fixed crash if joystick functions are passed a NULL joystick
In particular this affects the doomsday game engine if no joystick or
gamepad is attached.
(cherry picked from commit 0dfdf1f3f2
)
[smcv: Also included minor adjustment from https://github.com/libsdl-org/SDL/pull/9233]
This commit is contained in:
@@ -1313,14 +1313,16 @@ const char *SDL_JoystickName(SDL_Joystick *joystick)
|
|||||||
const SDL_SteamVirtualGamepadInfo *info;
|
const SDL_SteamVirtualGamepadInfo *info;
|
||||||
|
|
||||||
SDL_LockJoysticks();
|
SDL_LockJoysticks();
|
||||||
|
{
|
||||||
|
CHECK_JOYSTICK_MAGIC(joystick, NULL);
|
||||||
|
|
||||||
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
|
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
|
||||||
if (info) {
|
if (info) {
|
||||||
retval = info->name;
|
retval = info->name;
|
||||||
} else {
|
} else {
|
||||||
CHECK_JOYSTICK_MAGIC(joystick, NULL);
|
|
||||||
|
|
||||||
retval = joystick->name;
|
retval = joystick->name;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
SDL_UnlockJoysticks();
|
SDL_UnlockJoysticks();
|
||||||
|
|
||||||
/* FIXME: Really we should reference count this name so it doesn't go away after unlock */
|
/* FIXME: Really we should reference count this name so it doesn't go away after unlock */
|
||||||
@@ -3102,6 +3104,9 @@ Uint16 SDL_JoystickGetVendor(SDL_Joystick *joystick)
|
|||||||
const SDL_SteamVirtualGamepadInfo *info;
|
const SDL_SteamVirtualGamepadInfo *info;
|
||||||
|
|
||||||
SDL_LockJoysticks();
|
SDL_LockJoysticks();
|
||||||
|
{
|
||||||
|
CHECK_JOYSTICK_MAGIC(joystick, 0);
|
||||||
|
|
||||||
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
|
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
|
||||||
if (info) {
|
if (info) {
|
||||||
vendor = info->vendor_id;
|
vendor = info->vendor_id;
|
||||||
@@ -3110,6 +3115,7 @@ Uint16 SDL_JoystickGetVendor(SDL_Joystick *joystick)
|
|||||||
|
|
||||||
SDL_GetJoystickGUIDInfo(guid, &vendor, NULL, NULL, NULL);
|
SDL_GetJoystickGUIDInfo(guid, &vendor, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
SDL_UnlockJoysticks();
|
SDL_UnlockJoysticks();
|
||||||
|
|
||||||
return vendor;
|
return vendor;
|
||||||
@@ -3121,6 +3127,9 @@ Uint16 SDL_JoystickGetProduct(SDL_Joystick *joystick)
|
|||||||
const SDL_SteamVirtualGamepadInfo *info;
|
const SDL_SteamVirtualGamepadInfo *info;
|
||||||
|
|
||||||
SDL_LockJoysticks();
|
SDL_LockJoysticks();
|
||||||
|
{
|
||||||
|
CHECK_JOYSTICK_MAGIC(joystick, 0);
|
||||||
|
|
||||||
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
|
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
|
||||||
if (info) {
|
if (info) {
|
||||||
product = info->product_id;
|
product = info->product_id;
|
||||||
@@ -3129,6 +3138,7 @@ Uint16 SDL_JoystickGetProduct(SDL_Joystick *joystick)
|
|||||||
|
|
||||||
SDL_GetJoystickGUIDInfo(guid, NULL, &product, NULL, NULL);
|
SDL_GetJoystickGUIDInfo(guid, NULL, &product, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
SDL_UnlockJoysticks();
|
SDL_UnlockJoysticks();
|
||||||
|
|
||||||
return product;
|
return product;
|
||||||
|
Reference in New Issue
Block a user