I’ve been trying to do a UI addition to a couple of my projects and have been dealing with periodic crashing so I decided to go back to the start to see if I could pinpoint when the crashing starts. Starting fresh from the monomer-starter I made the following change that simply adds a forkIO around the Monomer IO and within a minute it segmentation faults.
I think monomer uses SDL2, and I don’t think SDL2 likes being switched around OS threads (which forkIO allows for since it spawns an M:N green thread).
iirc I had this same issue running my SDL2 games in ghci. forkOS was the fix.
Notice that in sdl2 (the C library, not even the Haskell bindings) event polling, rendering, etc… should be done in the same thread. sdl2 official documentation advice to always run in the main thread, so even if you forkOS you might run into problems.
I have had no trouble running in a bound thread in ghci fwiw!
The only “trouble” was GC pauses that weren’t present in the final executable. I think it’s because ghci has an additional working set in the heap (all the loaded code & state I guess?). Luckily the non-moving collector fixed that. Thank goodness for -xn!