From f30392da5bd51da3fb8b74eab3f9193d0194ee2a Mon Sep 17 00:00:00 2001 From: Mathieu Eyraud <70028899+meyraud705@users.noreply.github.com> Date: Thu, 5 Oct 2023 19:44:15 +0200 Subject: [PATCH] Fix assertion in LINUX_JoystickSetSensorsEnabled() Calling LINUX_JoystickSetSensorsEnabled() after the joystick is unplugged will trigger this assertion. --- src/joystick/linux/SDL_sysjoystick.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index ade45ed901..fea2006954 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -1565,7 +1565,9 @@ static int LINUX_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enab } if (enabled) { - SDL_assert(joystick->hwdata->item_sensor); + if (joystick->hwdata->item_sensor == NULL) { + return SDL_SetError("Sensors unplugged."); + } joystick->hwdata->fd_sensor = open(joystick->hwdata->item_sensor->path, O_RDONLY | O_CLOEXEC, 0); if (joystick->hwdata->fd_sensor < 0) { return SDL_SetError("Couldn't open sensor file %s.", joystick->hwdata->item_sensor->path);