From 9298e5ad0ec6818b5f3d922f85bdf12c791d5c48 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Tue, 11 Mar 2025 22:16:03 +0100 Subject: [PATCH] Fixed memory leak in editor. --- src/AnimGraphEditor/AnimGraphEditor.cc | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/AnimGraphEditor/AnimGraphEditor.cc b/src/AnimGraphEditor/AnimGraphEditor.cc index cbecc33..3305482 100644 --- a/src/AnimGraphEditor/AnimGraphEditor.cc +++ b/src/AnimGraphEditor/AnimGraphEditor.cc @@ -364,6 +364,14 @@ void AnimGraphEditorRenderSidebar( } } +void AnimGraphEditorResetHierarchyStack() { + sEditorState.hierarchyStack.clear(); + sEditorState.hierarchyStack.push_back(sEditorState.rootGraphResource); + sEditorState.hierarchyStack[sEditorState.hierarchyStackIndex] = + sEditorState.hierarchyStack.back(); + sEditorState.hierarchyStackIndex = 0; +} + void AnimGraphEditorClear() { if (ax::NodeEditor::GetCurrentEditor() != nullptr) { ax::NodeEditor::ClearSelection(); @@ -378,11 +386,7 @@ void AnimGraphEditorClear() { sEditorState.rootGraphResource->m_name = "Root"; sEditorState.isGraphLoadedThisFrame = true; - sEditorState.hierarchyStack.clear(); - sEditorState.hierarchyStack.push_back(sEditorState.rootGraphResource); - sEditorState.hierarchyStack[sEditorState.hierarchyStackIndex] = - sEditorState.hierarchyStack.back(); - sEditorState.hierarchyStackIndex = 0; + AnimGraphEditorResetHierarchyStack(); } void BlendTreeEditorNodePopup() { @@ -453,8 +457,13 @@ void AnimGraphEditorMenuBar() { } if (ImGui::Button("Load")) { AnimGraphEditorClear(); - sEditorState.rootGraphResource->LoadFromFile("editor_graph.json"); - sEditorState.isGraphLoadedThisFrame = true; + + delete sEditorState.rootGraphResource; + + sEditorState.rootGraphResource = + AnimGraphResource::CreateFromFile("editor_graph.json"); + + AnimGraphEditorResetHierarchyStack(); } if (ImGui::Button("Clear")) { AnimGraphEditorClear();