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
|
liftIO $ do
|
||||||
joyIds <- mapM SDL.getJoystickID js
|
joyIds <- mapM SDL.getJoystickID js
|
||||||
logIO Verbose $ "These are the Joysticks connected: " ++ show joyIds
|
logIO Verbose $ "These are the Joysticks connected: " ++ show joyIds
|
||||||
[d] <- filterM (\j -> fmap (== which) (SDL.getJoystickID j)) js
|
d <- filterM (\j -> fmap (== which) (SDL.getJoystickID j)) js
|
||||||
logIO Verbose $ "disconnected joysticks: " ++ show d
|
if not (null d)
|
||||||
|
then do
|
||||||
|
logIO Verbose $ "disconnected joysticks: " ++ show (head d)
|
||||||
logIO Verbose $ "Disconnecting Joystick " ++ show which
|
logIO Verbose $ "Disconnecting Joystick " ++ show which
|
||||||
SDL.closeJoystick d
|
SDL.closeJoystick (head d)
|
||||||
njoys <- filterM (\j -> return $ d /= j) js
|
njoys <- filterM (\j -> return $ head d /= j) js
|
||||||
logIO Verbose $ "returning joysticks: " ++ show njoys
|
logIO Verbose $ "returning joysticks: " ++ show njoys
|
||||||
return njoys
|
return njoys
|
||||||
|
else do
|
||||||
|
logIO Error $ "Error while disconnecting Joystick"
|
||||||
|
return js
|
||||||
joystickAutoDisconnect js _ = return js
|
joystickAutoDisconnect js _ = return js
|
||||||
|
|
Loading…
Reference in a new issue