From 0fe8415bb433dc5880dbd87595e08ce96b5bc7cb Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 27 Apr 2021 11:56:02 +0200 Subject: [PATCH] Add assert if font loading fails during rendering --- src/fontdesc.c | 8 ++++++++ src/renderer.c | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/fontdesc.c b/src/fontdesc.c index 56244af8..d1d0825f 100644 --- a/src/fontdesc.c +++ b/src/fontdesc.c @@ -1,4 +1,5 @@ #include +#include #include "fontdesc.h" #include "renderer.h" @@ -37,6 +38,13 @@ int font_desc_get_tab_size(FontDesc *font_desc) { static void load_scaled_font(FontDesc *font_desc, int index, int scale) { RenFont *font = ren_load_font(font_desc->filename, scale * font_desc->size, font_desc->options); + if (!font) { + /* The font was able to load when initially loaded using renderer.load.font. + If now is no longer available we just abort the application. */ + fprintf(stderr, "Fatal error: unable to load font %s. Application will abort.\n", + font_desc->filename); + exit(1); + } font_desc->cache[index].font = font; font_desc->cache[index].scale = scale; } diff --git a/src/renderer.c b/src/renderer.c index 3bd237c0..b2adc044 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -74,7 +74,8 @@ static int get_surface_scale() { int w_points, h_points; SDL_GL_GetDrawableSize(renderer.window, &w_pixels, &h_pixels); SDL_GetWindowSize(renderer.window, &w_points, &h_points); - // FIXME: this assert is too harsh. + /* We consider that the ratio pixel/point will always be an integer and + it is the same along the x and the y axis. */ assert(w_pixels % w_points == 0 && h_pixels % h_points == 0 && w_pixels / w_points == h_pixels / h_points); return w_pixels / w_points; }