From: Steinar H. Gunderson Date: Sun, 19 Feb 2012 14:44:16 +0000 (+0100) Subject: Fix a crash when not finding any fonts. X-Git-Url: https://git.sesse.net/?p=ccbs;a=commitdiff_plain;h=fab2f8bf846b85607862a2126a68bc4228d8f75d Fix a crash when not finding any fonts. --- diff --git a/bigscreen/fonts.cpp b/bigscreen/fonts.cpp index bbc4c1a..8cee589 100644 --- a/bigscreen/fonts.cpp +++ b/bigscreen/fonts.cpp @@ -53,8 +53,9 @@ void init_freetype() FT_Face face; if (FT_New_Face(library, font_list[i].c_str(), 0, &face)) { fprintf(stderr, "Warning: Couldn't open '%s', some glyphs might not be available\n", font_list[i].c_str()); + } else { + faces[font_list[i]] = face; } - faces[font_list[i]] = face; } } } @@ -96,7 +97,7 @@ unsigned my_draw_text(const widestring &str, unsigned char *buf, double size, co ypos = ypos * screen_height / LOGICAL_SCREEN_HEIGHT; for (widestring::const_iterator i = str.begin(); i != str.end(); ++i) { - int glyph_index; + int glyph_index = 0; for (std::vector::const_iterator j = fonts.begin(); j != fonts.end(); ++j) { glyph_index = FT_Get_Char_Index(*j, *i); if (glyph_index == 0) @@ -113,7 +114,7 @@ unsigned my_draw_text(const widestring &str, unsigned char *buf, double size, co break; } if (glyph_index == 0) { - std::fprintf(stderr, "Warning: Could not find a glyph in any font for U+%x, ignoring\n", *i); + std::fprintf(stderr, "Warning: Could not find a glyph in any font for U+%04x, ignoring\n", *i); continue; }