Font and MessageManager::Lock clarification

#1

Hi !

I just update juce_graphics module to Juce 5 developer branch.
And I find the “new” clever assert in Font::getStringWidthFloat and Font::getGlyphPositions:

// This call isn't thread-safe when there's a message thread running
jassert (MessageManager::getInstanceWithoutCreating() == nullptr
           || MessageManager::getInstanceWithoutCreating()->currentThreadHasLockedMessageManager());

I’m wondering why this is not thread safe ?
Is it because of ReferenceCountedObjectPtr<SharedFontInternal> Font::font;
or because of TypefaceCache::getInstance() ?

If it is related to TypefaceCache, may be we should move this assert in Font::getTypeface()
method instead because there is other extra callers that should be protected:
Font::getAscent() Font::getAvailableStyles() Font::getHeightToPointsFactor()

I’m looking at this code because I made some offscreen Juce::Image Font rendering in my OpenGL thread, so I protect my caller code with:

juce::MessageManager::Lock managerLock;
managerLock.enter();
... // text rendering
managerLock.exit();

Hoping that client of my code already start the dispatch loop. (I do not know the way to check it, help is welcome here)

Thanks in advance for your advices.

NB: I already have related issue 3 years before with Juce 4 here:

All the bests

0 Likes

#2

Hi
Nobody can enlighten me on this?

Best regards

0 Likes