From 66fa7e7411991241ea63b61e2b5b34a9732c786c Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 6 Jul 2017 11:45:26 +0100 Subject: [PATCH] Added some assertions to catch use of some Font methods on background threads --- modules/juce_graphics/fonts/juce_Font.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/juce_graphics/fonts/juce_Font.cpp b/modules/juce_graphics/fonts/juce_Font.cpp index b80a306a07..8d43600250 100644 --- a/modules/juce_graphics/fonts/juce_Font.cpp +++ b/modules/juce_graphics/fonts/juce_Font.cpp @@ -625,6 +625,10 @@ int Font::getStringWidth (const String& text) const float Font::getStringWidthFloat (const String& text) const { + // This call isn't thread-safe when there's a message thread running + jassert (MessageManager::getInstanceWithoutCreating() == nullptr + || MessageManager::getInstanceWithoutCreating()->currentThreadHasLockedMessageManager()); + auto w = getTypeface()->getStringWidth (text); if (font->kerning != 0.0f) @@ -635,6 +639,10 @@ float Font::getStringWidthFloat (const String& text) const void Font::getGlyphPositions (const String& text, Array& glyphs, Array& xOffsets) const { + // This call isn't thread-safe when there's a message thread running + jassert (MessageManager::getInstanceWithoutCreating() == nullptr + || MessageManager::getInstanceWithoutCreating()->currentThreadHasLockedMessageManager()); + getTypeface()->getGlyphPositions (text, glyphs, xOffsets); if (auto num = xOffsets.size())