OSX font corruption

#1

I am making a plugin, which loads a TTF font from a JUCE BinaryResource.
I am loading this font inside the “PluginEditor” class, the following way:

defaultTypefacePtr = Typeface::createSystemTypefaceFor(BinaryData::Roboto_Light_ttf, BinaryData::Roboto_Light_ttfSize);

In other words: This line is run every time I open the plugin window.

My problem: The font gets corrupted, after opening the plugin window several times inside a DAW. By corrupted I mean that letters are missing and that I even get crashes inside the font routines. For example, it can crash inside “TTrueTypeFontDataHandler::GetGlyphData”

I found a solution to my problem. But I am not sure yet, why it works:
I solved my problem, by first clearing the font cache with a call to clearTypefaceCache():

Typeface::clearTypefaceCache();
defaultTypefacePtr = Typeface::createSystemTypefaceFor(BinaryData::Roboto_Light_ttf, BinaryData::Roboto_Light_ttfSize);

So apparently, the font cache is kept, even if the plugin GUI window is destructed. When you open the plugin GUI window again, it is going to use the same font cache. But for some reason, this font cache gets corrupted over time. Clearing the cache every time, solves this.

Is this cache corruption a known problem? Or am I doing something wrong?
I only seem to get this on OSX. On Windows it works fine without clearing the typeface cache first.

I am on OSX 10.14.4 and JUCE 5.4.3 Build Date 22 Feb 2019.

2 Likes
Occasional glyph crash
#2

Known issue, it happens in our app quite regularly. The exact cause or solution isn’t known. I’ve been trying to reproduce the problem in a minimal program, but so far have been failing.

#3

Hi G-Mon,

Thanks for your answer. Good to know, I am not the only one experiencing this.

#4

We’ve tried for years to nail this one down, but it’s very hard to reproduce. I assume it’s a bug in the OSX font system but exactly what triggers it, and how we’d work around it is very hard to guess. We’ll get it one day!

1 Like
#5

Trying to reproduce this I discovered that creating 32766 Typeface objects will hang inside CTFontManagerRegisterGraphicsFont. Not sure if related.

#6

Thanks Jules.
Fingers crossed!