Hi!
I think I found a threading issue with Graphics::drawText
My application have two threads:
- The main thread displaying a lots of juce::Component
- The second thread starting early at application initialization, does internal computation without display anything.
This second thread does some off-screen text rendering on local juce::Image like this:
static juce::Image createImageFromText(const String& text) { juce::Image image(juce::Image::ARGB, 320, 180, false); juce::Graphics g(image); g.fillAll(juce::Colours::black); g.setColour(juce::Colours::red); g.setFont(juce::Font(12)); g.drawText(text, 0, 0, 320, 180, juce::Justification::centred, false); return image; }
Sometime, at application start-up, the second thread crash in the following callstack:
juce::WindowsTypeface::getOutlineForGlyph+0x140 juce::Typeface::getEdgeTableForGlyph+0x52 juce::RenderingHelpers::CachedGlyphEdgeTable<juce::RenderingHelpers::SoftwareRendererSavedState>::generate+0x87 juce::RenderingHelpers::GlyphCache<juce::RenderingHelpers::CachedGlyphEdgeTable<juce::RenderingHelpers::SoftwareRendererSavedState>,juce::RenderingHelpers::SoftwareRendererSavedState>::findOrCreateGlyph+0x7f juce::RenderingHelpers::GlyphCache<juce::RenderingHelpers::CachedGlyphEdgeTable<juce::RenderingHelpers::SoftwareRendererSavedState>,juce::RenderingHelpers::SoftwareRendererSavedState>::drawGlyph+0x29 juce::RenderingHelpers::SoftwareRendererSavedState::drawGlyph+0xaf juce::GlyphArrangement::draw+0x111 juce::GlyphArrangement::draw+0x28 juce::Graphics::drawText+0x10d juce::Graphics::drawText+0x40 juce::Graphics::drawText+0x49 createImageFromText+0x127
It seems that the static GlyphCache& class GlyphCache::getInstance() function in juce_RenderingHelpers.h is not robust to multi-threaded initialization race condition.
Inherited class from GlyphCache do not seems to benefit from the powerfull juce_DeclareSingleton/juce_ImplementSingleton marco as others multi-threaded singleton in Juce.
Is it a design choice ?
Is juce::Graphics can only be created in the main thread ?
My application running on Windows 7 64bit or Windows 10 64bit
My application do not call the juce_opengl module.
I'm building the last Juce version in 64bit with JUCE_DLL=1 and JUCE_USE_DIRECTWRITE=0
With Visual Studio 2010 SP1 or Visual Studio 2015 update 1.
(I encounter crash with both compiler in both Windows platform)
Thanks in advance for your help on this subject.
Regards,