From 1f9f09ce7903ee2b7cec6b0ab7bf62cf2c486997 Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 7 Aug 2024 09:59:08 -0400 Subject: [PATCH] add sdl_deleter.h for RAII SDL resources --- src/app/core/utils/sdl_deleter.h | 26 ++++++++++++++++++++++++++ src/app/emu/debug/emu.cc | 21 +++------------------ 2 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 src/app/core/utils/sdl_deleter.h diff --git a/src/app/core/utils/sdl_deleter.h b/src/app/core/utils/sdl_deleter.h new file mode 100644 index 00000000..ab72b358 --- /dev/null +++ b/src/app/core/utils/sdl_deleter.h @@ -0,0 +1,26 @@ +#ifndef YAZE_APP_CORE_UTILS_SDL_DELETER_H_ +#define YAZE_APP_CORE_UTILS_SDL_DELETER_H_ + +namespace yaze { +namespace app { +namespace core { + +struct sdl_deleter { + void operator()(SDL_Window *p) const { + if (p) { + SDL_DestroyWindow(p); + } + } + void operator()(SDL_Renderer *p) const { + if (p) { + SDL_DestroyRenderer(p); + } + } + void operator()(SDL_Texture *p) const { SDL_DestroyTexture(p); } +}; + +} // namespace core +} // namespace app +} // namespace yaze + +#endif // YAZE_APP_CORE_UTILS_SDL_DELETER_H_ \ No newline at end of file diff --git a/src/app/emu/debug/emu.cc b/src/app/emu/debug/emu.cc index 888ca42d..068db31b 100644 --- a/src/app/emu/debug/emu.cc +++ b/src/app/emu/debug/emu.cc @@ -5,10 +5,6 @@ #endif #include -#include "absl/status/status.h" -#include "absl/strings/str_format.h" -#include "imgui/imgui.h" -#include "imgui_memory_editor.h" #include #include @@ -25,25 +21,14 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_format.h" +#include "app/core/utils/sdl_deleter.h" #include "app/emu/snes.h" #include "app/rom.h" +#include "imgui/imgui.h" +#include "imgui_memory_editor.h" using namespace yaze::app; -struct sdl_deleter { - void operator()(SDL_Window *p) const { - if (p) { - SDL_DestroyWindow(p); - } - } - void operator()(SDL_Renderer *p) const { - if (p) { - SDL_DestroyRenderer(p); - } - } - void operator()(SDL_Texture *p) const { SDL_DestroyTexture(p); } -}; - int main(int argc, char **argv) { absl::InitializeSymbolizer(argv[0]);