]> git.sesse.net Git - ccbs/commitdiff
Fix a crash when not finding any fonts.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 19 Feb 2012 14:44:16 +0000 (15:44 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 19 Feb 2012 14:44:16 +0000 (15:44 +0100)
bigscreen/fonts.cpp

index bbc4c1a0d4305e5133c7626d8ace838435080439..8cee589dfc679225abd4b951e2a312589ee76227 100644 (file)
@@ -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<FT_Face>::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;
                }