From 590d3b9e3a2abdd37270ca64689a64c4e879fbe6 Mon Sep 17 00:00:00 2001 From: Steve Bennetts Date: Thu, 15 Oct 2009 14:14:46 -0700 Subject: EXT-1279 Crash if font file not found. Added getFontDefault() to llfontgl.h --HG-- branch : branch-test --- indra/llrender/llfontgl.cpp | 7 +++++++ indra/llrender/llfontgl.h | 1 + indra/llrender/llfontregistry.cpp | 5 ++++- indra/llui/llconsole.cpp | 5 +++++ indra/llui/llui.cpp | 7 ++++++- indra/newview/llfolderviewitem.cpp | 4 ++++ 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp index f7bab3de67..16c99599cf 100644 --- a/indra/llrender/llfontgl.cpp +++ b/indra/llrender/llfontgl.cpp @@ -910,6 +910,13 @@ LLFontGL* LLFontGL::getFontByName(const std::string& name) } } +//static +LLFontGL* LLFontGL::getFontDefault() +{ + return getFontSansSerif(); // Fallback to sans serif as default font +} + + // static std::string LLFontGL::getFontPathSystem() { diff --git a/indra/llrender/llfontgl.h b/indra/llrender/llfontgl.h index ad84b6d641..d6d6436aee 100644 --- a/indra/llrender/llfontgl.h +++ b/indra/llrender/llfontgl.h @@ -167,6 +167,7 @@ public: static LLFontGL* getFont(const LLFontDescriptor& desc); // Use with legacy names like "SANSSERIF_SMALL" or "OCRA" static LLFontGL* getFontByName(const std::string& name); + static LLFontGL* getFontDefault(); // default fallback font static std::string getFontPathLocal(); static std::string getFontPathSystem(); diff --git a/indra/llrender/llfontregistry.cpp b/indra/llrender/llfontregistry.cpp index 45573cd817..7a3d6ec4f2 100644 --- a/indra/llrender/llfontregistry.cpp +++ b/indra/llrender/llfontregistry.cpp @@ -380,7 +380,10 @@ LLFontGL *LLFontRegistry::createFont(const LLFontDescriptor& desc) LLFontDescriptor nearest_exact_desc = *match_desc; nearest_exact_desc.setSize(norm_desc.getSize()); font_reg_map_t::iterator it = mFontMap.find(nearest_exact_desc); - if (it != mFontMap.end()) + // If we fail to find a font in the fonts directory, it->second might be NULL. + // We shouldn't construcnt a font with a NULL mFontFreetype. + // This may not be the best solution, but it at least prevents a crash. + if (it != mFontMap.end() && it->second != NULL) { llinfos << "-- matching font exists: " << nearest_exact_desc.getName() << " size " << nearest_exact_desc.getSize() << " style " << ((S32) nearest_exact_desc.getStyle()) << llendl; diff --git a/indra/llui/llconsole.cpp b/indra/llui/llconsole.cpp index 285ce82d2d..e0053b4cc7 100644 --- a/indra/llui/llconsole.cpp +++ b/indra/llui/llconsole.cpp @@ -120,6 +120,11 @@ void LLConsole::setFontSize(S32 size_index) { mFont = LLFontGL::getFontSansSerifHuge(); } + // Make sure the font exists + if (mFont == NULL) + { + mFont = LLFontGL::getFontDefault(); + } for(paragraph_t::iterator paragraph_it = mParagraphs.begin(); paragraph_it != mParagraphs.end(); paragraph_it++) { diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp index c89e5944fa..eb1b60244d 100644 --- a/indra/llui/llui.cpp +++ b/indra/llui/llui.cpp @@ -1954,7 +1954,12 @@ namespace LLInitParam return fontp; } } - + + if (mData.mValue == NULL) + { + mData.mValue = LLFontGL::getFontDefault(); + } + // default to current value return mData.mValue; } diff --git a/indra/newview/llfolderviewitem.cpp b/indra/newview/llfolderviewitem.cpp index ee5fba5ace..ea1275aad1 100644 --- a/indra/newview/llfolderviewitem.cpp +++ b/indra/newview/llfolderviewitem.cpp @@ -70,6 +70,10 @@ LLFontGL* LLFolderViewItem::getLabelFontForStyle(U8 style) { LLFontDescriptor labelfontdesc("SansSerif", "Small", style); rtn = LLFontGL::getFont(labelfontdesc); + if (!rtn) + { + rtn = LLFontGL::getFontDefault(); + } sFonts[style] = rtn; } return rtn; -- cgit v1.2.3