Obscure font-related iOS bug causes deadlock (+fix)

I hit an extremely obscure iOS bug this morning. A deadlock on app startup, to do with loading a font. It happened when I add a font via Projucer as an Xcode Resource (as well as a Binary Resource).

I found a solution via this SO post, which linked to this article that provides a bit more detail.

The fix for me was to add the following line to the beginning of the OSXTypeface constructor: [UIFont systemFontOfSize:12];

    OSXTypeface (const void* data, size_t dataSize)
        : Typeface (String(), String()),
          fontRef (nullptr),
          ctFontRef (nullptr),
          fontHeightToPointsFactor (1.0f),
          renderingTransform (CGAffineTransformIdentity),
          isMemoryFont (true),
          dataCopy (data, dataSize),
          attributedStringAtts (nullptr),
          ascent (0.0f),
          unitsToHeightScaleFactor (0.0f)
    {
        // We can't use CFDataCreate here as this triggers a false positive in ASAN
        // so copy the data manually and use CFDataCreateWithBytesNoCopy
        CFDataRef cfData = CFDataCreateWithBytesNoCopy (kCFAllocatorDefault, (const UInt8*) dataCopy.getData(),
                                                        (CFIndex) dataCopy.getSize(), kCFAllocatorNull);
        CGDataProviderRef provider = CGDataProviderCreateWithCFData (cfData);
        CFRelease (cfData);

        [UIFont systemFontOfSize:12]; // <-- bug fix, from http://www.openradar.me/18778790
        
        fontRef = CGFontCreateWithDataProvider (provider);
        CGDataProviderRelease (provider);
        ...
1 Like

Thanks adamski!! I just pushed your fix to develop.

1 Like