From: Holger Schemel Date: Mon, 9 Dec 2024 18:21:06 +0000 (+0100) Subject: fixed (and added warning when) trying to free already freed textures X-Git-Tag: 4.4.0.0-test-6~23 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=9586f78c56577bc70ff191b7a6037879c5038317;p=rocksndiamonds.git fixed (and added warning when) trying to free already freed textures --- 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