diff --git a/src/app/core/utils/sdl_deleter.h b/src/app/core/utils/sdl_deleter.h index e1f467ea..31062595 100644 --- a/src/app/core/utils/sdl_deleter.h +++ b/src/app/core/utils/sdl_deleter.h @@ -7,10 +7,31 @@ namespace yaze { namespace app { namespace core { +/** + * @brief Deleter for SDL_Window and SDL_Renderer. + */ struct SDL_Deleter { void operator()(SDL_Window *p) const { SDL_DestroyWindow(p); } void operator()(SDL_Renderer *p) const { SDL_DestroyRenderer(p); } - void operator()(SDL_Texture *p) const { SDL_DestroyTexture(p); } +}; + +/** + * @brief Deleter for SDL_Texture. + */ +struct SDL_Texture_Deleter { + void operator()(SDL_Texture *p) const { + if (p) SDL_DestroyTexture(p); + } +}; + +/** + * @brief Deleter for SDL_Surface. + */ +struct SDL_Surface_Deleter { + void operator()(SDL_Surface *p) const { + // Check if the surface is not null + if (p) SDL_FreeSurface(p); + } }; } // namespace core diff --git a/src/app/gfx/bitmap.cc b/src/app/gfx/bitmap.cc index 8606c5e5..590a8275 100644 --- a/src/app/gfx/bitmap.cc +++ b/src/app/gfx/bitmap.cc @@ -16,6 +16,9 @@ namespace yaze { namespace app { namespace gfx { +using core::SDL_Surface_Deleter; +using core::SDL_Texture_Deleter; + namespace { void GrayscalePalette(SDL_Palette *palette) { for (int i = 0; i < 8; i++) { diff --git a/src/app/gfx/bitmap.h b/src/app/gfx/bitmap.h index 11f503fd..a7e4a82c 100644 --- a/src/app/gfx/bitmap.h +++ b/src/app/gfx/bitmap.h @@ -11,6 +11,7 @@ #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "app/core/constants.h" +#include "app/core/utils/sdl_deleter.h" #include "app/gfx/snes_palette.h" namespace yaze { @@ -193,22 +194,6 @@ class Bitmap { auto set_active(bool active) { active_ = active; } private: - struct SDL_Texture_Deleter { - void operator()(SDL_Texture *p) const { - if (p != nullptr) { - SDL_DestroyTexture(p); - } - } - }; - - struct SDL_Surface_Deleter { - void operator()(SDL_Surface *p) const { - if (p != nullptr) { - SDL_FreeSurface(p); - } - } - }; - int width_ = 0; int height_ = 0; int depth_ = 0;