From 9586f78c56577bc70ff191b7a6037879c5038317 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 9 Dec 2024 19:21:06 +0100 Subject: [PATCH] fixed (and added warning when) trying to free already freed textures --- src/libgame/sdl.c | 15 +++++++++++++++ src/libgame/sdl.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 4c485263..8bb732ab 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -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) diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 23eb13ca..c2b55c24 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -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 -- 2.34.1