From: Holger Schemel Date: Mon, 9 Dec 2024 18:16:11 +0000 (+0100) Subject: cleanup of functions to free bitmap surfaces and textures X-Git-Tag: 4.4.0.0-test-6~24 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=95d821a7fb8b9c8a418e96edb4d51b4ebfd4adaa;p=rocksndiamonds.git cleanup of functions to free bitmap surfaces and textures --- diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index e401a65c..4c485263 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -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) diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 1545f686..23eb13ca 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -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);