Fixed crash if joystick functions are passed a NULL joystick

main
Sam Lantinga 2023-12-27 11:25:54 -08:00
parent 4ce935b910
commit 0dfdf1f3f2
1 changed files with 29 additions and 17 deletions

View File

@ -1521,13 +1521,17 @@ const char *SDL_GetJoystickName(SDL_Joystick *joystick)
const SDL_SteamVirtualGamepadInfo *info;
SDL_LockJoysticks();
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
if (info) {
retval = info->name;
} else {
{
CHECK_JOYSTICK_MAGIC(joystick, NULL);
retval = joystick->name;
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
if (info) {
retval = info->name;
} else {
CHECK_JOYSTICK_MAGIC(joystick, NULL);
retval = joystick->name;
}
}
SDL_UnlockJoysticks();
@ -3247,13 +3251,17 @@ Uint16 SDL_GetJoystickVendor(SDL_Joystick *joystick)
const SDL_SteamVirtualGamepadInfo *info;
SDL_LockJoysticks();
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
if (info) {
vendor = info->vendor_id;
} else {
SDL_JoystickGUID guid = SDL_GetJoystickGUID(joystick);
{
CHECK_JOYSTICK_MAGIC(joystick, 0);
SDL_GetJoystickGUIDInfo(guid, &vendor, NULL, NULL, NULL);
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
if (info) {
vendor = info->vendor_id;
} else {
SDL_JoystickGUID guid = SDL_GetJoystickGUID(joystick);
SDL_GetJoystickGUIDInfo(guid, &vendor, NULL, NULL, NULL);
}
}
SDL_UnlockJoysticks();
@ -3266,13 +3274,17 @@ Uint16 SDL_GetJoystickProduct(SDL_Joystick *joystick)
const SDL_SteamVirtualGamepadInfo *info;
SDL_LockJoysticks();
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
if (info) {
product = info->product_id;
} else {
SDL_JoystickGUID guid = SDL_GetJoystickGUID(joystick);
{
CHECK_JOYSTICK_MAGIC(joystick, 0);
SDL_GetJoystickGUIDInfo(guid, NULL, &product, NULL, NULL);
info = SDL_GetJoystickInstanceVirtualGamepadInfo(joystick->instance_id);
if (info) {
product = info->product_id;
} else {
SDL_JoystickGUID guid = SDL_GetJoystickGUID(joystick);
SDL_GetJoystickGUIDInfo(guid, NULL, &product, NULL, NULL);
}
}
SDL_UnlockJoysticks();