Package: libsdl1.2debian
Version: 1.2.14-6.1
Severity: normal
Tags: patch upstream
Problem description:
SDL opens joystick device only once at startup. If usb connection is
lost
for some reason (bad USB cable, cheap gamepad, little brother tripping
on the wire)
- your game is ruined. Input device file is gone for a short time,
opened file handle is no longer valid. Kernel re-creates device file
after connection is back, but libsdl does not re-open it.
Steps to reproduce: plug USB joystick, run SDL-based application that
uses joystick, unplug your joystick for a brief time and plug it back
in.
The patch tries to re-open the device if read operation reports bad file
/ no such device. I know about possible caveats (like, the new device
can have different name, multiple joysticks can re-appear in different
order or maybe the device plugged is totally different one), but still I
believe anything is better then forcing user to start the game from the
very beginning. Especially annoying if user is 3 years old and can't
start the game on his own.
I (OK, not I but my son) tested it for a week, and it work just fine
with mame, mess, mednafen and supertux.
It also works for lenny version of libsdl, but you have to
#define SDL_INPUT_LINUXEV 1
#define NO_LOGICAL_JOYSTICKS
, because patch only fixes this flag combination (the one that is used in
squeeze build).
-- System Information:
Debian Release: squeeze/sid
APT prefers testing
APT policy: (990, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.6.32-5-openvz-686 (SMP w/1 CPU core)
Locale: LANG=ru_RU.UTF-8, LC_CTYPE=ru_RU.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages libsdl1.2debian depends on:
ii libsdl1.2debian-oss 1.2.14-6.1 Simple DirectMedia Layer (with X11
libsdl1.2debian recommends no packages.
libsdl1.2debian suggests no packages.
-- no debconf information
diff --git a/joystick/linux/SDL_sysjoystick.c b/joystick/linux/SDL_sysjoystick.c
index 5960c84..8ed70d0 100644
--- a/joystick/linux/SDL_sysjoystick.c
+++ b/joystick/linux/SDL_sysjoystick.c
@@ -25,6 +25,7 @@
/* This is the system specific header for the SDL joystick API */
+#include
#include
#include
#include
@@ -1133,6 +1134,12 @@ static __inline__ void EV_HandleEvents(SDL_Joystick *joystick)
}
}
}
+ if (ENODEV == errno || EBADF == errno)
+ {
+ // try reopening:
+ joystick->hwdata->fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0);
+ fcntl(joystick->hwdata->fd, F_SETFL, O_NONBLOCK);
+ }
}
#endif /* SDL_INPUT_LINUXEV */