From c30081b2f9d36739f96c36fa477ff8af0480f5c1 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 16 Sep 2012 17:21:01 +0200 Subject: defined SDL_FREESURFACE_SAFE() --- main.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index f6950e1..ffd182c 100644 --- a/main.c +++ b/main.c @@ -32,6 +32,13 @@ SDL_UnlockSurface(SURFACE); \ } while (0) +#define SDL_FREESURFACE_SAFE(SURFACE) do { \ + if (SURFACE) { \ + SDL_FreeSurface(SURFACE); \ + SURFACE = NULL; \ + } \ +} while (0) + #define SDL_ERROR(FMT, ...) do { \ fprintf(stderr, "%s(%d): " FMT ": %s\n", \ __FILE__, __LINE__, ##__VA_ARGS__, SDL_GetError()); \ @@ -309,15 +316,8 @@ layer_image_new(const char *file) static void layer_image_change(struct layer_image *ctx, const char *file) { - if (ctx->surf_alpha) { - SDL_FreeSurface(ctx->surf_alpha); - ctx->surf_alpha = NULL; - } - - if (ctx->surf) { - SDL_FreeSurface(ctx->surf); - ctx->surf = NULL; - } + SDL_FREESURFACE_SAFE(ctx->surf_alpha); + SDL_FREESURFACE_SAFE(ctx->surf); if (!file || !*file) return; @@ -410,10 +410,7 @@ layer_image_alpha(struct layer_image *ctx, float opacity) } if (alpha == SDL_ALPHA_OPAQUE) { - if (ctx->surf_alpha) { - SDL_FreeSurface(ctx->surf_alpha); - ctx->surf_alpha = NULL; - } + SDL_FREESURFACE_SAFE(ctx->surf_alpha); return; } -- cgit v1.2.3