From e454fde2aeb9f50cae4ae6d3237aac6553540ff5 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 27 Jul 2012 12:42:04 -0700 Subject: Fix bug 6888377: crash in GetUnitsPerEm on locale change The underlying problem is that no SkScalerContext objects existed at the time shapeFontRun is called immediately after a locale change from en to ja (apparently the dumping of the cache caused all these to be deallocated), so gFTLibrary was null (and the call tio ref_ft_face assumes that it's initialized). There's a pattern for calls which might not necessarily be called from a scaler context (GetAdvancedTypefaceMetrics is one such), to explicitly check for an uninitialized library, and create one for the length of the call if so. This patch changes GetUnitsPerEm to follow this pattern. Change-Id: I19a4b6fa49fad0aeacc04bf971101aacca6bc94f --- src/ports/SkFontHost_FreeType.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index da00d51..eb05959 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -685,6 +685,13 @@ void SkFontHost::FilterRec(SkScalerContext::Rec* rec) { #ifdef SK_BUILD_FOR_ANDROID uint32_t SkFontHost::GetUnitsPerEm(SkFontID fontID) { SkAutoMutexAcquire ac(gFTMutex); + FT_Library libInit = NULL; + if (gFTCount == 0) { + if (!InitFreetype()) + sk_throw(); + libInit = gFTLibrary; + } + SkAutoTCallIProc ftLib(libInit); SkFaceRec *rec = ref_ft_face(fontID); uint16_t unitsPerEm = 0; -- cgit v1.1