mirror of https://github.com/libsdl-org/SDL
Fixed crash if joystick functions are passed a NULL joystick
This commit is contained in:
parent
4ce935b910
commit
0dfdf1f3f2
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue