Skip to content

Commit

Permalink
Fixed|OS X|libgui: Potential hang while drawing text
Browse files Browse the repository at this point in the history
One should only lock the CoreText font cache for as short time as
possible. Making a log entry while the cache was locked was unwise
because a flush might be triggered, causing text drawing operations
that need font information.
  • Loading branch information
skyjake committed Jul 3, 2014
1 parent 79a233e commit 3b70a24
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions doomsday/libgui/src/text/coretextnativefont_macx.cpp
Expand Up @@ -79,24 +79,32 @@ struct CoreTextFontCache : public Lockable

CTFontRef getFont(String const &postScriptName, dfloat pointSize)
{
DENG2_GUARD(this);
CTFontRef font;

Key const key(postScriptName, pointSize);
if(fonts.contains(key))
// Only lock the cache while accessing the fonts database. If we keep the
// lock while printing log output, a flush might occur, which might in turn
// lead to text rendering and need for font information -- causing a hang.
{
// Already got it.
return fonts[key];
}
DENG2_GUARD(this);

// Get a reference to the font.
CFStringRef name = CFStringCreateWithCharacters(nil, (UniChar *) postScriptName.data(),
postScriptName.size());
CTFontRef font = CTFontCreateWithName(name, pointSize, nil);
CFRelease(name);
Key const key(postScriptName, pointSize);
if(fonts.contains(key))
{
// Already got it.
return fonts[key];
}

// Get a reference to the font.
CFStringRef name = CFStringCreateWithCharacters(nil, (UniChar *) postScriptName.data(),
postScriptName.size());
font = CTFontCreateWithName(name, pointSize, nil);
CFRelease(name);

fonts.insert(key, font);
}

LOG_GL_VERBOSE("Cached native font '%s' size %.1f") << postScriptName << pointSize;

fonts.insert(key, font);
return font;
}

Expand Down

0 comments on commit 3b70a24

Please sign in to comment.