Reputation: 9726
I am trying to compile and run a simple SDL program on OSX 10.8.2, SDL 1.2.15, GHC 7.4.2, haskell SDL bindings 0.6.4:
import Graphics.UI.SDL as SDL
main :: IO ()
main = do
screen <- setVideoMode 640 480 32 [SWSurface]
hello <- loadBMP "hello.bmp"
blitSurface hello Nothing screen Nothing
SDL.flip screen
delay 2000
It compiles (ghc test.hs
) without erros, but when I try to run it, I get the following exception:
$ ./test
2012-11-30 12:37:29.453 test[8995:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1000) creating CGSWindow on line 259'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8cf060a6 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff88e813f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8cf05e7c +[NSException raise:format:] + 204
3 AppKit 0x00007fff87e41c29 _NSCreateWindowWithOpaqueShape2 + 655
4 AppKit 0x00007fff87e40420 -[NSWindow _commonAwake] + 2002
5 AppKit 0x00007fff87dfee62 -[NSWindow _commonInitFrame:styleMask:backing:defer:] + 1763
6 AppKit 0x00007fff87dfdfaf -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1568
7 AppKit 0x00007fff87dfd97f -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45
8 libSDL-1.2.0.dylib 0x0000000101dc6bf6 -[SDL_QuartzWindow initWithContentRect:styleMask:backing:defer:] + 279
9 libSDL-1.2.0.dylib 0x0000000101dc4ac9 QZ_SetVideoMode + 2629
10 libSDL-1.2.0.dylib 0x0000000101dbb903 SDL_SetVideoMode + 886
11 test 0x0000000101b9d6b2 smJx_info + 50
)
libc++abi.dylib: terminate called throwing an exception
As far as I understand, this has something to do with main()
-replacement trickery SDL performs. I looked at several other SDL-using Haskell apps; the ones that I managed to compile show the same behavior (which may point to some problem with my particular configuration). One exception is Eternal10Seconds which uses -no-hs-main
ghc option and some .c
/.h
magic. Is this necessary, or there is more clear way to make things work?
Upvotes: 3
Views: 707
Reputation: 9726
Sorry for the informational noise, but I managed to solve it myself. It seems that .c
magic is inevitable, but it requires certain efforts to make it working with cabal
. Based on the example from haskell-SDL repo and TimePiece, I put together a template. I am planning to extend it a bit to make it truly cross-platform (because I need it myself anyway).
Upvotes: 2