aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-09-16 17:21:01 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-09-16 17:21:01 +0200
commitc30081b2f9d36739f96c36fa477ff8af0480f5c1 (patch)
tree0bbc5ec594d1cee8ffea353cc3e6df7c5c2bd9f3
parenta1563222f86d115db939d82f8f7b5b3687f8d5f9 (diff)
downloadosc-graphics-c30081b2f9d36739f96c36fa477ff8af0480f5c1.tar.gz
defined SDL_FREESURFACE_SAFE()
-rw-r--r--main.c23
1 files changed, 10 insertions, 13 deletions
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;
}