Add assert if font loading fails during rendering

This commit is contained in:
Francesco Abbate 2021-04-27 11:56:02 +02:00
parent 8b9fbecd74
commit 0fe8415bb4
2 changed files with 10 additions and 1 deletions

View File

@ -1,4 +1,5 @@
#include <stddef.h>
#include <stdlib.h>
#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;
}

View File

@ -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;
}