fix joystick disconnect crash
This commit is contained in:
parent
f822b5cabb
commit
fa2501021c
1 changed files with 12 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue