diff --git a/utils.cpp b/utils.cpp index 0d04645..b10c8fd 100644 --- a/utils.cpp +++ b/utils.cpp @@ -12,30 +12,26 @@ TTF_Font *read_and_alloc_font(const char *path, int pt_size) { TTF_Font *out; SDL_RWops *rw; - Uint8 *data = (Uint8*)malloc(1 * 1024*1024); + Uint8 *data = (Uint8*)xmalloc(1 * 1024*1024); FILE *fp = fopen(path, "r"); - if (!data) { - fprintf(stderr, "Malloc failed\n"); - exit(1); - } if (!fp) { fprintf(stderr, "Could not open font %s\n", path); - exit(1); + return NULL; } fread(data, 1, 1 * 1024 * 1024, fp); rw = SDL_RWFromMem(data, 1 * 1024 * 1024); if (!rw) { fprintf(stderr, "Could not create RW: %s\n", SDL_GetError()); - exit(1); + free(data); + return NULL; } out = TTF_OpenFontRW(rw, 1, pt_size); if (!out) { fprintf(stderr, "TTF: Unable to create font %s (%s)\n", path, TTF_GetError()); - exit(1); } fclose(fp); diff --git a/utils.hh b/utils.hh index 4e6243b..cf93778 100644 --- a/utils.hh +++ b/utils.hh @@ -10,6 +10,8 @@ class Font; +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x)) + #define BUG_ON(cond) #define panic(x...) do \