[racket] Figured out the Mac OS X crashing issue for liballegro / libsdl / etc...

From: Jon Rafkind (rafkind at cs.utah.edu)
Date: Sun Jan 13 17:35:28 EST 2013

Does the entire application have to live within the dynamic extent of the `initialize-ns-app' call or just making the screen?

(initialize-ns-app (lambda () (create-display))
(do-rest-of-program)

or

(initialize-ns-app (lambda () (create-display) (do-rest-of-program))

On 01/13/2013 03:14 PM, Danny Yoo wrote:
> Hi Jon,
>
>
> [Also CCing the Racket mailing list.  For folks who are writing
> bindings to graphical libraries such as SDL, the following should be
> relevant.]
>
>
> When using the Allegro bindings on Mac OS X, the user will see an
> exception on screen instantiation unless the program's running under a
> Cocoa context.
>
> Folks from other communities have figured out how to solve this.  In
> particular, the PySDL folks have a small module to set it up.
> (https://github.com/albertz/PySDL/blob/master/SDL/__init__.py)
>
> I've ported the heart of this to Racket:
>
>     https://gist.github.com/4526379
>
> (Comment the use of initialize-ns-app in that code; I added it to make
> sure it was getting called.)
>
>
> initialize-ns-app provides a Cocoa context in which all the rest of
> the graphical library usage must occur on Mac OS X.  So, typically
> code will look like:
>
>    ;; load foreign libraries...
>
>    (initiaize-ns-app
>       (lambda ()
>          ;; Now it's safe to create the screen in here ...
>       ))
>
>
>
>
> If you don't do something like this, you'll see this exception as soon
> as you start initializing the screen:
>
> 2013-01-13 15:07:22.716 racket[26263:707] *** Terminating app due to
> uncaught exception 'NSInternalInconsistencyException', reason: 'Error
> (1000) creating CGSWindow on line 259'
> *** First throw call stack:
> (
> 	0   CoreFoundation                      0x00007fff8e6ca0a6
> __exceptionPreprocess + 198
> 	1   libobjc.A.dylib                     0x00007fff9681e3f0
> objc_exception_throw + 43
> 	2   CoreFoundation                      0x00007fff8e6c9e7c
> +[NSException raise:format:] + 204
> 	3   AppKit                              0x00007fff951b2c29
> _NSCreateWindowWithOpaqueShape2 + 655
> 	4   AppKit                              0x00007fff951b1420 -[NSWindow
> _commonAwake] + 2002
> 	5   AppKit                              0x00007fff9516fe62 -[NSWindow
> _commonInitFrame:styleMask:backing:defer:] + 1763
> 	6   AppKit                              0x00007fff9516efaf -[NSWindow
> _initContent:styleMask:backing:defer:contentView:] + 1568
> 	7   AppKit                              0x00007fff9516e97f -[NSWindow
> initWithContentRect:styleMask:backing:defer:] + 45
> 	8   SDL                                 0x0000000102f515cc
> SDL_SoftStretch + 24672
> 	9   SDL                                 0x0000000102f4fe38
> SDL_SoftStretch + 18636
> 	10  SDL                                 0x0000000102f44da1
> SDL_SetVideoMode + 892
> 	11  Racket                              0x00000001002be82c ffi_call_unix64 + 76
> 	12  ???                                 0x00007fff5fbfd8d0 0x0 +
> 140734799796432
> )
> libc++abi.dylib: terminate called throwing an exception
> Abort trap: 6


Posted on the users mailing list.