diff --git a/src/app/core/controller.cc b/src/app/core/controller.cc index f8e24351..65770e4f 100644 --- a/src/app/core/controller.cc +++ b/src/app/core/controller.cc @@ -157,7 +157,8 @@ void Controller::DoRender() const { SDL_RenderPresent(renderer_.get()); } -void Controller::OnExit() const { +void Controller::OnExit() { + master_editor_.Shutdown(); Mix_CloseAudio(); ImGui_ImplSDLRenderer2_Shutdown(); ImGui_ImplSDL2_Shutdown(); diff --git a/src/app/core/controller.h b/src/app/core/controller.h index 6046dc3c..1a2d3c9e 100644 --- a/src/app/core/controller.h +++ b/src/app/core/controller.h @@ -27,7 +27,7 @@ class Controller { void OnInput(); void OnLoad(); void DoRender() const; - void OnExit() const; + void OnExit(); private: struct sdl_deleter { diff --git a/src/app/editor/master_editor.h b/src/app/editor/master_editor.h index 8d645ee6..05fc5964 100644 --- a/src/app/editor/master_editor.h +++ b/src/app/editor/master_editor.h @@ -34,6 +34,9 @@ class MasterEditor : public SharedROM { public: void SetupScreen(std::shared_ptr renderer); void UpdateScreen(); + void Shutdown() { + overworld_editor_.Shutdown(); + } private: void DrawFileDialog(); diff --git a/src/app/gfx/bitmap.h b/src/app/gfx/bitmap.h index 944b7969..33eaa008 100644 --- a/src/app/gfx/bitmap.h +++ b/src/app/gfx/bitmap.h @@ -46,6 +46,32 @@ class Bitmap { this->pixel_data_[position] = value; } + void Cleanup() { + // Reset texture_ + if (texture_) { + texture_.reset(); + } + + // Reset surface_ and its pixel data + if (surface_) { + surface_->pixels = nullptr; + surface_.reset(); + } + + // Reset data_ + data_.clear(); + + // Reset other members if necessary + active_ = false; + pixel_data_ = nullptr; + width_ = 0; + height_ = 0; + depth_ = 0; + data_size_ = 0; + palette_.Clear(); // assuming there's a Clear() method or similar on + // SNESPalette + } + int width() const { return width_; } int height() const { return height_; } auto size() const { return data_size_; }