Typeface::GetOutlineForGlyph() crashes, using Multithreads


#1

Hi Jules,
I am calling Typeface::GetOutlineForGlyph() from main thread and another thread, which is crashing. I am using JUCE 1_53…

class ThreadCheck : public juce::Thread
{
public:
	ThreadCheck ():Thread("")
	{
	}

	void run()
	{
		juce::Font font(14.0);
		juce::Path path;
		Typeface* ptr = font.getTypeface();
		while(true)
			ptr->getOutlineForGlyph(0, path);
	}
};

Place this code section in any function getting called from Main Thread

juce::Font font(14.0);
Typeface* ptr = font.getTypeface();

ThreadCheck thread;
thread.startThread();

juce::Path path1;
while(true)
   ptr->getOutlineForGlyph(0, path1);

I upgraded from JUCE 1_51 to 1_53… In 1_51 it is not crashing…


#2

None of the GUI-related code is designed to be thread-safe, it’d be impractical to add locking to every possible graphics function that you might call. If you need to call something like that from a background thread then you’d need to wrap it in a MessageManagerLock.

Only by pure luck.


#3

I am not using this call to render to Component, i am basically rendering thumbnail of a path in a thread… So i will render into image not to Component.
Getting only the path for glyph doesn’t look like GUI functionality… It looks like only the data access…
So can’t we make a lock on typeface while getting outline?


#4

Well, I suppose the typeface cache could be made thread-safe… I’ll have a look next time I’m doing some work in there.


#5

Well, I too faced the same issue…
And I’ve faced this issue mostly on Windows and not that much on Mac…
Aside from TypefaceCache, even the WindowsTypeface does not look thread safe.
Won’t there be issues when GetGlyphIndices and GetGlyphOutline (using the same dc) are called from multiple threads??