[HOpenGL] [bug] error in unmarshalMouseButton

Claude Heiland-Allen claudiusmaximus at goto10.org
Mon Jun 15 20:43:10 EDT 2009


Hi,

I'm developing a mouse-driven user interface using HOpenGL/GLUT.

However, it sometimes crashes if I'm too clumsy on my laptop's trackpad:

$ ./gulci
gulci: unmarshalMouseButton: illegal value 5
$ ./gulci
gulci: unmarshalMouseButton: illegal value 6


The offending code calls error:

--8<--
unmarshalMouseButton :: CInt -> MouseButton
unmarshalMouseButton x
    | x == glut_LEFT_BUTTON = LeftButton
    | x == glut_MIDDLE_BUTTON = MiddleButton
    | x == glut_RIGHT_BUTTON = RightButton
    | x == glut_WHEEL_UP = WheelUp
    | x == glut_WHEEL_DOWN = WheelDown
    | otherwise = error ("unmarshalMouseButton: illegal value " ++ show x)
--8<--
http://www.haskell.org/ghc/dist/current/docs/libraries/GLUT/src/Graphics-UI-GLUT-Types.html


Suggested fix:

modify the MouseButton type to have an additional constructor, eg:

data MouseButton = ... | OtherMouseButton CInt

and handle that case in the obvious way in the (un)marshal code (and 
suitably adjust any other code that pattern matches on MouseButton)


BTW, I noticed I'm not the first to suffer from this crash issue, see 
for example #haskell IRC log from 2008-05-16.


Claude
-- 
http://claudiusmaximus.goto10.org



More information about the HOpenGL mailing list