Skip to content

Commit

Permalink
Fixed crash if joystick functions are passed a NULL joystick
Browse files Browse the repository at this point in the history
In particular this affects the doomsday game engine if no joystick or
gamepad is attached.

(cherry picked from commit 0dfdf1f)
[smcv: Also included minor adjustment from libsdl-org#9233]
  • Loading branch information
slouken authored and smcv committed Mar 9, 2024
1 parent 528b712 commit 4edc3cc
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions src/joystick/SDL_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -1313,13 +1313,15 @@ const char *SDL_JoystickName(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 {
retval = joystick->name;
}
}
SDL_UnlockJoysticks();

Expand Down Expand Up @@ -3102,13 +3104,17 @@ Uint16 SDL_JoystickGetVendor(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_JoystickGetGUID(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_JoystickGetGUID(joystick);

SDL_GetJoystickGUIDInfo(guid, &vendor, NULL, NULL, NULL);
}
}
SDL_UnlockJoysticks();

Expand All @@ -3121,13 +3127,17 @@ Uint16 SDL_JoystickGetProduct(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_JoystickGetGUID(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_JoystickGetGUID(joystick);

SDL_GetJoystickGUIDInfo(guid, NULL, &product, NULL, NULL);
}
}
SDL_UnlockJoysticks();

Expand Down

0 comments on commit 4edc3cc

Please sign in to comment.