Closed jasonhemann closed 1 year ago
The problem seems to be something about the implementation of Mac libraries. Here's a relatively small program that crashes in the same way on my machine:
#lang racket
(require ffi/unsafe
ffi/unsafe/objc)
(define (load-appkit)
(void (ffi-lib (format "/System/Library/Frameworks/AppKit.framework/AppKit"))))
(define CTFontCollectionCreateFromAvailableFonts
(get-ffi-obj 'CTFontCollectionCreateFromAvailableFonts
(ffi-lib (format "/System/Library/Frameworks/CoreText.framework/CoreText"))
(_fun _pointer -> _pointer)))
(CTFontCollectionCreateFromAvailableFonts #f)
(load-appkit)
(import-class NSApplication)
(tell NSApplication sharedApplication) ; crash happens here
But if you swap the order of the calls to CTFontCollectionCreateFromAvailableFonts
and load-appkit
, there's no crash. It seems that maybe CTFontCollectionCreateFromAvailableFonts
is sensitive to whether AppKit hash been loaded (which potentially makes sense, given that it's supposed to get fonts available to the current application), and then loading AppKit later puts things in a bad state for NSApplication
. Applications don't normally load AppKit and access NSApplication
dynamically, so that's why it wouldn't affect many Mac programs.
The answer is probably to force a load of AppKit on Mac OS before the call to pango_cairo_font_map_new
, which is the part of Pango that calls CTFontCollectionCreateFromAvailableFonts
. Or just loading AppKit on initialization of the Pango library is simplest and probably fine.
Comparatively small file:
Where the scribble file is:
and the racket file is simply:
When trying to build the document, I see the following error:
I'm on Racket 8.6, XCode Version 12.4 (12D4e), and MacOS 10.15.7.