Skip to content

Running GLUT code in GHCi yields NSInternalInconsistencyException

I tried running some GLUT code in macOS Sierra (Version 10.12.5 (16F73)) and ran into a strange error. If you're willing to use cabal-install, you can just do this:

$ cabal install GLFW-0.5.2.5

And run this module in with runghc:

-- GLUT.hs
module Main where

import Graphics.UI.GLUT (($=), getArgsAndInitialize, createWindow, displayCallback, mainLoop)

main :: IO ()
main = do
  (_progName, _args) <- getArgsAndInitialize
  _window <- createWindow "Hello World"
  displayCallback $= return ()
  mainLoop
$ runghc GLUT.hs
2017-05-19 12:03:02.199 ghc[24628:669385] GLUT Fatal Error: internal error: NSInternalInconsistencyException, reason: nextEventMatchingMask should only be called from the Main Thread!

On the other hand, compiling and running the executable works without issue.

Alternatively, you can compile the attached files, which require no dependencies:

$ ghc HsGLUT.c GLUT2.hs
[1 of 1] Compiling Main             ( GLUT2.hs, GLUT2.o )
Linking GLUT2 ...

$ ghci HsGLUT.o GLUT2.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /Users/rscott/.ghci
[1 of 1] Compiling Main             ( GLUT2.hs, interpreted )
Ok, modules loaded: Main.
λ> main
2017-05-19 12:06:15.365 ghc[24671:670166] GLUT Fatal Error: internal error: NSInternalInconsistencyException, reason: nextEventMatchingMask should only be called from the Main Thread!
Trac metadata
Trac field Value
Version 8.0.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHCi
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information