Skip to content

Commit

Permalink
Don't crash if font not found
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Senichev <[email protected]>
  • Loading branch information
artemsen committed Jul 7, 2024
1 parent 8c34cc7 commit ac23b57
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,10 @@ void font_init(void)
char file[256];
const FT_F26Dot6 size = ctx.size * 64;

if (!search_font_file(ctx.name, file, sizeof(file))) {
return;
}
if (FT_Init_FreeType(&ctx.lib) != 0) {
return;
}
if (FT_New_Face(ctx.lib, file, 0, &ctx.face) != 0) {
if (!search_font_file(ctx.name, file, sizeof(file)) ||
FT_Init_FreeType(&ctx.lib) != 0 ||
FT_New_Face(ctx.lib, file, 0, &ctx.face) != 0) {
fprintf(stderr, "Unable to load font %s\n", ctx.name);
return;
}

Expand All @@ -139,7 +136,13 @@ bool font_render(const char* text, struct text_surface* surface)
size_t x;
wchar_t* wide;
const wchar_t* ptr;
const size_t space_size = ctx.face->size->metrics.y_ppem / SPACE_WH_REL;
size_t space_size;

if (!ctx.face) {
return false;
}

space_size = ctx.face->size->metrics.y_ppem / SPACE_WH_REL;

wide = str_to_wide(text, NULL);
if (!wide) {
Expand Down

0 comments on commit ac23b57

Please sign in to comment.