Don't exit on font load failure, add ARRAY_SIZE

This commit is contained in:
simon.kagstrom 2010-01-06 07:47:51 +00:00
parent a286b4b355
commit d3ed78078c
2 changed files with 6 additions and 8 deletions

View File

@ -12,30 +12,26 @@ TTF_Font *read_and_alloc_font(const char *path, int pt_size)
{ {
TTF_Font *out; TTF_Font *out;
SDL_RWops *rw; SDL_RWops *rw;
Uint8 *data = (Uint8*)malloc(1 * 1024*1024); Uint8 *data = (Uint8*)xmalloc(1 * 1024*1024);
FILE *fp = fopen(path, "r"); FILE *fp = fopen(path, "r");
if (!data) {
fprintf(stderr, "Malloc failed\n");
exit(1);
}
if (!fp) { if (!fp) {
fprintf(stderr, "Could not open font %s\n", path); fprintf(stderr, "Could not open font %s\n", path);
exit(1); return NULL;
} }
fread(data, 1, 1 * 1024 * 1024, fp); fread(data, 1, 1 * 1024 * 1024, fp);
rw = SDL_RWFromMem(data, 1 * 1024 * 1024); rw = SDL_RWFromMem(data, 1 * 1024 * 1024);
if (!rw) if (!rw)
{ {
fprintf(stderr, "Could not create RW: %s\n", SDL_GetError()); fprintf(stderr, "Could not create RW: %s\n", SDL_GetError());
exit(1); free(data);
return NULL;
} }
out = TTF_OpenFontRW(rw, 1, pt_size); out = TTF_OpenFontRW(rw, 1, pt_size);
if (!out) if (!out)
{ {
fprintf(stderr, "TTF: Unable to create font %s (%s)\n", fprintf(stderr, "TTF: Unable to create font %s (%s)\n",
path, TTF_GetError()); path, TTF_GetError());
exit(1);
} }
fclose(fp); fclose(fp);

View File

@ -10,6 +10,8 @@
class Font; class Font;
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
#define BUG_ON(cond) #define BUG_ON(cond)
#define panic(x...) do \ #define panic(x...) do \