cleanup of functions to free bitmap surfaces and textures
authorHolger Schemel <holger.schemel@virtion.de>
Mon, 9 Dec 2024 18:16:11 +0000 (19:16 +0100)
committerHolger Schemel <holger.schemel@virtion.de>
Mon, 9 Dec 2024 12:17:06 +0000 (13:17 +0100)
src/libgame/sdl.c
src/libgame/sdl.h

index e401a65c11de74ab4295184a8ac4142aace4de00..4c485263ca166d305a20c245fa3ae41ca58a104b 100644 (file)
@@ -550,15 +550,26 @@ void SDLCreateBitmapTextures(Bitmap *bitmap)
   if (bitmap == NULL)
     return;
 
-  if (bitmap->texture)
-    SDL_DestroyTexture(bitmap->texture);
-  if (bitmap->texture_masked)
-    SDL_DestroyTexture(bitmap->texture_masked);
+  SDLFreeBitmapTextures(bitmap);
 
   bitmap->texture        = SDLCreateTextureFromSurface(bitmap->surface);
   bitmap->texture_masked = SDLCreateTextureFromSurface(bitmap->surface_masked);
 }
 
+void SDLFreeBitmapSurfaces(Bitmap *bitmap)
+{
+  if (bitmap == NULL)
+    return;
+
+  if (bitmap->surface)
+    SDL_FreeSurface(bitmap->surface);
+  if (bitmap->surface_masked)
+    SDL_FreeSurface(bitmap->surface_masked);
+
+  bitmap->surface = NULL;
+  bitmap->surface_masked = NULL;
+}
+
 void SDLFreeBitmapTextures(Bitmap *bitmap)
 {
   if (bitmap == NULL)
@@ -573,6 +584,12 @@ void SDLFreeBitmapTextures(Bitmap *bitmap)
   bitmap->texture_masked = NULL;
 }
 
+void SDLFreeBitmapPointers(Bitmap *bitmap)
+{
+  SDLFreeBitmapSurfaces(bitmap);
+  SDLFreeBitmapTextures(bitmap);
+}
+
 void SDLInitVideoDisplay(void)
 {
   // set hint to select render driver as specified in setup config file
@@ -1044,25 +1061,6 @@ void SDLRedrawWindow(void)
   UpdateScreen_WithoutFrameDelay(NULL);
 }
 
-void SDLFreeBitmapPointers(Bitmap *bitmap)
-{
-  if (bitmap->surface)
-    SDL_FreeSurface(bitmap->surface);
-  if (bitmap->surface_masked)
-    SDL_FreeSurface(bitmap->surface_masked);
-
-  bitmap->surface = NULL;
-  bitmap->surface_masked = NULL;
-
-  if (bitmap->texture)
-    SDL_DestroyTexture(bitmap->texture);
-  if (bitmap->texture_masked)
-    SDL_DestroyTexture(bitmap->texture_masked);
-
-  bitmap->texture = NULL;
-  bitmap->texture_masked = NULL;
-}
-
 void SDLBlitSurface(SDL_Surface *src_surface, SDL_Surface *dst_surface,
                    int src_x, int src_y, int width, int height,
                    int dst_x, int dst_y)
index 1545f6865fbc80317f3e53af68c6a6cf8b27da39..23eb13ca87c4eabdedc5b57fb88e4b28023a0494 100644 (file)
@@ -403,7 +403,9 @@ SDL_Surface *SDLCreateNativeSurface(int, int, int);
 Bitmap *SDLGetBitmapFromSurface_WithMaskedColor(SDL_Surface *, int, int, int);
 Bitmap *SDLGetBitmapFromSurface(SDL_Surface *);
 void SDLCreateBitmapTextures(Bitmap *);
+void SDLFreeBitmapSurfaces(Bitmap *);
 void SDLFreeBitmapTextures(Bitmap *);
+void SDLFreeBitmapPointers(Bitmap *);
 
 SDL_Surface *SDL_DisplayFormat(SDL_Surface *);
 void SDLSetWindowScaling(int);
@@ -423,7 +425,6 @@ void SDLLimitScreenUpdates(boolean);
 void SDLInitVideoDisplay(void);
 void SDLInitVideoBuffer(boolean);
 boolean SDLSetVideoMode(boolean);
-void SDLFreeBitmapPointers(Bitmap *);
 void SDLBlitSurface(SDL_Surface *, SDL_Surface *, int, int, int, int, int, int);
 void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int);
 void SDLBlitTexture(Bitmap *, int, int, int, int, int, int, int);