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.