Add error-handling to Font.cpp
Prevents a crash on the Wii U port in 1280x720 when you try to open the pause menu. There's a giant delay now instead, and I'm not sure where it comes from. Still, it's an improvement.
This commit is contained in:
parent
a7f2ec6a5e
commit
231d1b93a7
1 changed files with 52 additions and 40 deletions
30
src/Font.cpp
30
src/Font.cpp
|
@ -963,17 +963,14 @@ static CachedGlyph* GetGlyphCached(FontObject *font_object, unsigned long unicod
|
|||
|
||||
if (glyph != NULL)
|
||||
{
|
||||
glyph->next = font_object->glyph_list_head;
|
||||
font_object->glyph_list_head = glyph;
|
||||
|
||||
unsigned int glyph_index = FT_Get_Char_Index(font_object->face, unicode_value);
|
||||
|
||||
#ifndef DISABLE_FONT_ANTIALIASING
|
||||
FT_Load_Glyph(font_object->face, glyph_index, FT_LOAD_RENDER);
|
||||
if (FT_Load_Glyph(font_object->face, glyph_index, FT_LOAD_RENDER) == 0)
|
||||
#else
|
||||
FT_Load_Glyph(font_object->face, glyph_index, FT_LOAD_RENDER | FT_LOAD_MONOCHROME);
|
||||
if (FT_Load_Glyph(font_object->face, glyph_index, FT_LOAD_RENDER | FT_LOAD_MONOCHROME) == 0)
|
||||
#endif
|
||||
|
||||
{
|
||||
glyph->unicode_value = unicode_value;
|
||||
glyph->x = font_object->face->glyph->bitmap_left;
|
||||
glyph->y = (FT_MulFix(font_object->face->ascender, font_object->face->size->metrics.y_scale) - font_object->face->glyph->metrics.horiBearingY + (64 / 2)) / 64;
|
||||
|
@ -981,8 +978,9 @@ static CachedGlyph* GetGlyphCached(FontObject *font_object, unsigned long unicod
|
|||
|
||||
FT_Bitmap bitmap;
|
||||
FT_Bitmap_New(&bitmap);
|
||||
FT_Bitmap_Convert(font_object->library, &font_object->face->glyph->bitmap, &bitmap, 1);
|
||||
|
||||
if (FT_Bitmap_Convert(font_object->library, &font_object->face->glyph->bitmap, &bitmap, 1) == 0)
|
||||
{
|
||||
switch (font_object->face->glyph->bitmap.pixel_mode)
|
||||
{
|
||||
case FT_PIXEL_MODE_GRAY:
|
||||
|
@ -1017,9 +1015,23 @@ static CachedGlyph* GetGlyphCached(FontObject *font_object, unsigned long unicod
|
|||
glyph->backend = RenderBackend_LoadGlyph(bitmap.buffer, bitmap.width, bitmap.rows, bitmap.pitch);
|
||||
|
||||
FT_Bitmap_Done(font_object->library, &bitmap);
|
||||
}
|
||||
|
||||
if (glyph->backend != NULL)
|
||||
{
|
||||
glyph->next = font_object->glyph_list_head;
|
||||
font_object->glyph_list_head = glyph;
|
||||
|
||||
return glyph;
|
||||
}
|
||||
}
|
||||
|
||||
FT_Bitmap_Done(font_object->library, &bitmap);
|
||||
}
|
||||
|
||||
free(glyph);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void UnloadCachedGlyphs(FontObject *font_object)
|
||||
|
@ -1095,7 +1107,7 @@ FontObject* LoadFont(const char *font_filename, unsigned int cell_width, unsigne
|
|||
|
||||
void DrawText(FontObject *font_object, RenderBackend_Surface *surface, int x, int y, unsigned long colour, const char *string)
|
||||
{
|
||||
if (font_object != NULL)
|
||||
if (font_object != NULL && surface != NULL)
|
||||
{
|
||||
const unsigned char colour_channels[3] = {(unsigned char)colour, (unsigned char)(colour >> 8), (unsigned char)(colour >> 16)};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue