Fixed memory leak in editor.

This commit is contained in:
Martin Felis 2025-03-11 22:16:03 +01:00
parent a1c4630ee7
commit 9298e5ad0e

View File

@ -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();