diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-16 17:21:01 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-16 17:21:01 +0200 |
commit | c30081b2f9d36739f96c36fa477ff8af0480f5c1 (patch) | |
tree | 0bbc5ec594d1cee8ffea353cc3e6df7c5c2bd9f3 | |
parent | a1563222f86d115db939d82f8f7b5b3687f8d5f9 (diff) | |
download | osc-graphics-c30081b2f9d36739f96c36fa477ff8af0480f5c1.tar.gz |
defined SDL_FREESURFACE_SAFE()
-rw-r--r-- | main.c | 23 |
1 files changed, 10 insertions, 13 deletions
@@ -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; } |