From 3ecfa15e4aa5427d77657e6ab03a4dfaa43821cf Mon Sep 17 00:00:00 2001 From: OusmBlueNinja <89956790+OusmBlueNinja@users.noreply.github.com> Date: Thu, 22 May 2025 10:14:46 -0500 Subject: [PATCH] Uses smart pointers for editor windows Replaces raw pointers with smart pointers for managing editor windows. This change improves memory management by ensuring proper deallocation of the Viewport and FileBrowser objects when the Editor shuts down, preventing potential memory leaks. --- src/core/types/all.h | 2 +- src/editor/Editor.cpp | 11 +++++------ src/editor/Editor.h | 5 +++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/core/types/all.h b/src/core/types/all.h index da0c9b9..b5d7e7d 100644 --- a/src/core/types/all.h +++ b/src/core/types/all.h @@ -8,4 +8,4 @@ static constexpr float PI = 3.14159265358979323846f; #include "vec2.h" #include "vec3.h" #include "vec4.h" -#include "mat4.h" +#include "mat4.h" \ No newline at end of file diff --git a/src/editor/Editor.cpp b/src/editor/Editor.cpp index 1717374..eefabca 100644 --- a/src/editor/Editor.cpp +++ b/src/editor/Editor.cpp @@ -11,6 +11,8 @@ #include "Windows/LoggerWindow.h" #include "Windows/Viewport.h" #include "Windows/FileBrowser.h" +#include "types/all.h" + namespace OX { @@ -40,8 +42,9 @@ namespace OX ImGui_ImplGlfw_InitForOpenGL(core.GetWindow().GetHandle(), true); ImGui_ImplOpenGL3_Init("#version 330 core"); - primaryViewport = new Viewport(); // The first time ive ever use the new keyword... - fileBrowser = new FileBrowser(); + fileBrowser = std::make_shared(); + primaryViewport = std::make_shared(); + } void Editor::Update(Core &core) @@ -161,11 +164,7 @@ namespace OX void Editor::Shutdown(Core &core) { - delete primaryViewport; - primaryViewport = nullptr; - delete fileBrowser; - fileBrowser = nullptr; ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); diff --git a/src/editor/Editor.h b/src/editor/Editor.h index df0f233..ffaebfc 100644 --- a/src/editor/Editor.h +++ b/src/editor/Editor.h @@ -7,6 +7,7 @@ #define OX_EDITOR_VERSION "Obsidian Editor (0.2.6)" #include "Layer.h" #include "Core.h" +#include "types/all.h" namespace OX @@ -28,8 +29,8 @@ namespace OX void Shutdown(Core &core) override; private: - Viewport* primaryViewport; - FileBrowser* fileBrowser; + std::shared_ptr primaryViewport; + std::shared_ptr fileBrowser; }; } // OX