creating an SDL2 window inside GHCI

Viewed 150

I have been using these SDL2 bindings. Although I can execute my compiled program, I cannot open a window from GHCi, no matter what I try. I've tried out the examples from the repository, but they have the same issue. The error message I keep getting is:

*** Exception: SDLCallFailed {sdlExceptionCaller = "SDL.Video.getWindowSurface", sdlFunction = "SDL_GetWindowSurface", sdlExceptionError = "Invalid window"}

If it's of any relevance I'm on macOS. I'm also not necessarily married to this library, and if there is a way to create a window from GHCi with a different library, I'd be interested.

1 Answers

I was using stack, and this fixed my issues:

stack ghci --ghci-options '-fno-ghci-sandbox'

I'm not exactly sure why this works, but I have a hunch it has something to do with ghci spawning threads, and SDL2 wanting the window in the main thread. If anyone has a better understanding of these things I'm very interested.

Related