diff --git a/src/Affection/Subsystems/AffectionJoystick.hs b/src/Affection/Subsystems/AffectionJoystick.hs index e9e1fae..05d40ca 100644 --- a/src/Affection/Subsystems/AffectionJoystick.hs +++ b/src/Affection/Subsystems/AffectionJoystick.hs @@ -101,11 +101,16 @@ joystickAutoDisconnect js (MsgJoystickDevice _ which SDL.JoyDeviceRemoved) = liftIO $ do joyIds <- mapM SDL.getJoystickID js logIO Verbose $ "These are the Joysticks connected: " ++ show joyIds - [d] <- filterM (\j -> fmap (== which) (SDL.getJoystickID j)) js - logIO Verbose $ "disconnected joysticks: " ++ show d - logIO Verbose $ "Disconnecting Joystick " ++ show which - SDL.closeJoystick d - njoys <- filterM (\j -> return $ d /= j) js - logIO Verbose $ "returning joysticks: " ++ show njoys - return njoys + d <- filterM (\j -> fmap (== which) (SDL.getJoystickID j)) js + if not (null d) + then do + logIO Verbose $ "disconnected joysticks: " ++ show (head d) + logIO Verbose $ "Disconnecting Joystick " ++ show which + SDL.closeJoystick (head d) + njoys <- filterM (\j -> return $ head d /= j) js + logIO Verbose $ "returning joysticks: " ++ show njoys + return njoys + else do + logIO Error $ "Error while disconnecting Joystick" + return js joystickAutoDisconnect js _ = return js