GLUT Fatal Error when using Haskell Graphics.Gloss

Viewed 286

I am following this tutorial and have created a demo.hs file with the following:

import Graphics.Gloss

window :: Display
window = InWindow "Nice Window" (200, 200) (10, 10)

background :: Color
background = white

drawing :: Picture
drawing = circle 80

main :: IO ()
main = display window background drawing

However, when I execute runhaskell demo.hs in my terminal, I get the following error message:

GLUT Fatal Error: internal error: NSInternalInconsistencyException, reason: nextEventMatchingMask should only be called from the Main Thread!

What does this error mean, and how can I fix it? I am using macOS Sierra version 10.12.5.

1 Answers

Start ghci with -fno-ghci-sandbox. This is because OpenGL uses thread local state, which doesn't work when the running program is in a different thread.

stack ghci --ghc-options -fno-ghci-sandbox

This worked for me.

(Credit to danielkroeni on reddit for this solution.)

Related