From 5595bb096439b0696de80c328854c9d948f10490 Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 15 Feb 2021 16:16:52 -0800 Subject: [PATCH] Add Graphics::destroy_buffers() These destroy all the buffers that are created on the Graphics class. Since these buffers can't be created at the same time as the rest of Graphics is (due to the fact that they require knowing the pixel format of the game screen), they can't be destroyed at the same as the rest of Graphics is, either. --- desktop_version/src/Graphics.cpp | 22 ++++++++++++++++++++++ desktop_version/src/Graphics.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index cac83323..a41e5421 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -170,6 +170,28 @@ void Graphics::destroy() #undef CLEAR_ARRAY } +void Graphics::destroy_buffers() +{ +#define FREE_SURFACE(SURFACE) \ + SDL_FreeSurface(SURFACE); \ + SURFACE = NULL; + + FREE_SURFACE(backBuffer) + FREE_SURFACE(footerbuffer) + FREE_SURFACE(ghostbuffer) + FREE_SURFACE(foregroundBuffer) + FREE_SURFACE(menubuffer) + FREE_SURFACE(warpbuffer) + FREE_SURFACE(warpbuffer_lerp) + FREE_SURFACE(towerbg.buffer) + FREE_SURFACE(towerbg.buffer_lerp) + FREE_SURFACE(titlebg.buffer) + FREE_SURFACE(titlebg.buffer_lerp) + FREE_SURFACE(tempBuffer) + +#undef FREE_SURFACE +} + int Graphics::font_idx(uint32_t ch) { if (font_positions.size() > 0) { std::map::iterator iter = font_positions.find(ch); diff --git a/desktop_version/src/Graphics.h b/desktop_version/src/Graphics.h index d6467f2c..1d574a69 100644 --- a/desktop_version/src/Graphics.h +++ b/desktop_version/src/Graphics.h @@ -19,6 +19,8 @@ public: void init(); void destroy(); + void destroy_buffers(); + GraphicsResources grphx; int bfontlen(uint32_t ch);