fixed (and added warning when) trying to free already freed textures
authorHolger Schemel <holger.schemel@virtion.de>
Mon, 9 Dec 2024 18:21:06 +0000 (19:21 +0100)
committerHolger Schemel <holger.schemel@virtion.de>
Mon, 9 Dec 2024 12:21:54 +0000 (13:21 +0100)
src/libgame/sdl.c
src/libgame/sdl.h

index 4c485263ca166d305a20c245fa3ae41ca58a104b..8bb732abf815c8a426fc435f29478def08a5da85 100644 (file)
@@ -554,6 +554,9 @@ void SDLCreateBitmapTextures(Bitmap *bitmap)
 
   bitmap->texture        = SDLCreateTextureFromSurface(bitmap->surface);
   bitmap->texture_masked = SDLCreateTextureFromSurface(bitmap->surface_masked);
+
+  // store renderer used to create textures
+  bitmap->renderer = sdl_renderer;
 }
 
 void SDLFreeBitmapSurfaces(Bitmap *bitmap)
@@ -575,6 +578,18 @@ void SDLFreeBitmapTextures(Bitmap *bitmap)
   if (bitmap == NULL)
     return;
 
+  // check renderer used to create textures
+  if (bitmap->renderer != NULL &&
+      bitmap->renderer != sdl_renderer &&
+      (bitmap->texture != NULL || bitmap->texture_masked != NULL))
+  {
+    // if renderer was destroyed, all its textures were also destroyed
+    bitmap->texture = NULL;
+    bitmap->texture_masked = NULL;
+
+    Warn("trying to free textures already freed by destroying renderer!");
+  }
+
   if (bitmap->texture)
     SDL_DestroyTexture(bitmap->texture);
   if (bitmap->texture_masked)
index 23eb13ca87c4eabdedc5b57fb88e4b28023a0494..c2b55c24818b1e9f180fd623a75cbfaeafce5328 100644 (file)
@@ -83,6 +83,8 @@ struct SDLSurfaceInfo
   SDL_Surface *surface_masked;
   SDL_Texture *texture;
   SDL_Texture *texture_masked;
+
+  SDL_Renderer *renderer;      // renderer used to create textures
 };
 
 struct MouseCursorInfo