Problems with fonts on MacOS since updating to JUCE7

Hello all,
I’ve been having difficulty recently with labels displaying garbled text (see image)
Screenshot 2022-08-31 161845
I’ve been using a custom lookAndFeel that overrides getTypefaceForFont like this:

  juce::Typeface::Ptr getTypefaceForFont(const juce::Font& font) override
  {
      auto name = font.getTypefaceName();
      auto isBold = font.isBold();
      if(name.compare("tall") == 0)
      {
          return condensedFont;
      }
      else if (isBold)
      {
          return boldFont;
      }
      else
      {
          return defaultFont;
      }
  }

Where each of the returned typefaces are set as constants in the LookAndFeel class using:
juce::Typeface::createSystemTypefaceFor()
I am then setting the lookAndFeel as the default lookAndFeel in the PluginEditor:
juce::LookAndFeel::setDefaultLookAndFeel(&customLnF);
This all used to work fine in JUCE6, but since updating to JUCE7 the text gets messed up often and is very easy to reproduce in Logic when using multiple instances of the AU plugin. It’s more difficult to reproduce on Windows, but it has happened once or twice.

One of the main problems is that the main information for using custom fonts comes from very confused forums, and there seems to be no up-to-date official guide.

Has anybody encountered this issue before and solved it? I’m at a loss.

1 Like

Seems I’m not the first with this problem… but not sure how disabling carbon would help with the windows build?
I’m also not sure why JUCE7 made it so much worse.

I’ll look over some old code tomorrow, because this sounds familiar. Does it happen after you close a gui? If you open 3 without closing any, are they all fine? Then when you close 1, the problem starts?

If so, I think I fixed this by wrapping the LnF and font in a sharedResourcePointer.

In the AU build the problem happens when I open a second instance seemingly regardless of any other factors. The original instance is fine, but the second one has garbled text.
On Windows it’s a bit more hit and miss, but seems to happen after the tooltip window appears.
In any case, the problem can be fixed by forcing a repaint by resizing the UI.

I haven’t looked into the sharedResourcePointer stuff, but I’ll check it out now.

In editor.h I had this. You can try it real quick. Not sure if it’s the same issue but good luck.


struct DefaultLookAndFeel
    {
        DefaultLookAndFeel()
        {
            juce::LookAndFeel::setDefaultLookAndFeel(&lnf);
            static auto font = juce::Typeface::createSystemTypefaceFor(BinaryData::RobotoRegular_ttf, BinaryData::RobotoRegular_ttfSize);
            lnf.setDefaultSansSerifTypeface(font);
        }

        ~DefaultLookAndFeel()
        {
            juce::LookAndFeel::setDefaultLookAndFeel(nullptr);
        }

        MyLookAndFeel lnf;

    };

    juce::SharedResourcePointer<DefaultLookAndFeel> defaultLnf;

This issue hasn’t been reported for at least a year now, so I thought it had been fixed. It would be extremely helpful if you could put together a small project that demonstrates the problem, along with some detailed steps to trigger the issue.

1 Like

I’ll see if I can put something together for you, but it’s a pretty big project. I’ll see what I can cut out. Is there a way to share these things privately?
I can tell you now that it was reproduceable when using JUCE6, but rare. However it is now easy to reproduce on the Mac builds using JUCE7. I initially found it by loading multiple instances of the same plugin in Logic after updating to JUCE7.
Using the sharedResourcePointer seems to have fixed it on Windows ( thanks @Fandusss ). I’ll be testing on Mac tonight.

You could send the project in a direct message to me as a .zip, or add me as a collaborator on a private repo on github (my handle is @reuk there too).

Make sure that you don’t put font in static struct.
Your font cache should be in something that uses DeleteAtShutdown otherwise font are messed when Juce is deleted but your DLL is still loaded and a new instance is loaded.

1 Like