Browse Source

GUI : correction du segfault si image manquante

master
Nikos 7 years ago
parent
commit
633d316112
1 changed files with 13 additions and 12 deletions
  1. +13
    -12
      gui.c

+ 13
- 12
gui.c View File

@@ -13,7 +13,8 @@
#define null_die(instruction, error) do if(!(instruction)) { fprintf(stderr, "(fatal) %s%s", error, "\n"); exit(1); } while(0)

SDL_Surface *IMG_LoadBoost(const char *path) {
SDL_Surface *tmp = IMG_Load(path), *ret;
SDL_Surface *tmp, *ret;
null_die(tmp = IMG_Load(path), "cannot load img");
ret = SDL_DisplayFormatAlpha(tmp);
SDL_FreeSurface(tmp);
return ret;
@@ -33,9 +34,9 @@ struct gui_resource_t display_start() {
SDL_WM_SetCaption("跳棋", NULL);

/* chargement images */
null_die(res.title_img = IMG_LoadBoost("img/title.png"), "cannot load title img");
null_die(res.bgnd_img = IMG_LoadBoost("img/background.png"), "cannot load bg img");
null_die(res.board_img = IMG_LoadBoost("img/board.png"), "cannot load board img");
res.title_img = IMG_LoadBoost("img/title.png");
res.bgnd_img = IMG_LoadBoost("img/background.png");
res.board_img = IMG_LoadBoost("img/board.png");

/* cas spécial pour la variation de transparence */
SDL_Surface *srcimg;
@@ -43,14 +44,14 @@ struct gui_resource_t display_start() {
res.msgboard_img = SDL_DisplayFormat(srcimg);
SDL_FreeSurface(srcimg);

null_die(res.nameboard_img = IMG_LoadBoost("img/nameboard.png"), "cannot load name board img");
null_die(res.pawn_img[0] = IMG_LoadBoost("img/pawn0-void.png"), "cannot load void pawn img");
null_die(res.pawn_img[1] = IMG_LoadBoost("img/pawn1-yellow.png"), "cannot load yellow pawn img");
null_die(res.pawn_img[2] = IMG_LoadBoost("img/pawn2-black.png"), "cannot load black pawn img");
null_die(res.pawn_img[3] = IMG_LoadBoost("img/pawn3-blue.png"), "cannot load blue pawn img");
null_die(res.pawn_img[4] = IMG_LoadBoost("img/pawn4-red.png"), "cannot load red pawn img");
null_die(res.pawn_img[5] = IMG_LoadBoost("img/pawn5-green.png"), "cannot load green pawn img");
null_die(res.pawn_img[6] = IMG_LoadBoost("img/pawn6-purple.png"), "cannot load purple pawn img");
res.nameboard_img = IMG_LoadBoost("img/nameboard.png");
res.pawn_img[0] = IMG_LoadBoost("img/pawn0-void.png");
res.pawn_img[1] = IMG_LoadBoost("img/pawn1-yellow.png");
res.pawn_img[2] = IMG_LoadBoost("img/pawn2-black.png");
res.pawn_img[3] = IMG_LoadBoost("img/pawn3-blue.png");
res.pawn_img[4] = IMG_LoadBoost("img/pawn4-red.png");
res.pawn_img[5] = IMG_LoadBoost("img/pawn5-green.png");
res.pawn_img[6] = IMG_LoadBoost("img/pawn6-purple.png");

/* chargement police de caractères */
null_die(res.font_big = TTF_OpenFont("img/cmunbmr.otf", 34), "cannot load font");


Loading…
Cancel
Save