From 3a7f470acfb38571b6dd59e18e9bcc6ac889a91c Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Fri, 22 Mar 2024 12:25:42 +0100 Subject: [PATCH] Fixed memory leak in ResourceSaveLoadMathGraphInputs test. --- src/AnimGraph/AnimGraphResource.h | 15 ++++++++++++++- tests/AnimGraphResourceTests.cc | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/AnimGraph/AnimGraphResource.h b/src/AnimGraph/AnimGraphResource.h index 6a0d1fd..b36488d 100644 --- a/src/AnimGraph/AnimGraphResource.h +++ b/src/AnimGraph/AnimGraphResource.h @@ -42,11 +42,24 @@ struct BlendTreeResource { std::vector m_nodes; std::vector m_connections; + ~BlendTreeResource() { CleanupNodes(); + } + void Reset() { - m_nodes.clear(); + CleanupNodes(); + m_connections.clear(); } + void CleanupNodes() { + for (AnimNodeResource& node_resource : m_nodes) { + delete node_resource.m_anim_node; + delete node_resource.m_socket_accessor; + } + + m_nodes.clear(); + } + void InitGraphConnectors() { m_nodes.push_back(AnimNodeResourceFactory("BlendTree")); m_nodes[0].m_name = "Outputs"; diff --git a/tests/AnimGraphResourceTests.cc b/tests/AnimGraphResourceTests.cc index 130eacf..d325d7e 100644 --- a/tests/AnimGraphResourceTests.cc +++ b/tests/AnimGraphResourceTests.cc @@ -413,7 +413,7 @@ TEST_CASE("ResourceSaveLoadMathGraphInputs", "[AnimGraphResource]") { AnimGraphResource graph_resource_loaded; graph_resource_loaded.LoadFromFile(filename); - BlendTreeResource graph_blend_tree_loaded = graph_resource_loaded.m_blend_tree_resource; + BlendTreeResource& graph_blend_tree_loaded = graph_resource_loaded.m_blend_tree_resource; const AnimNodeResource& graph_loaded_output_node = graph_blend_tree_loaded.m_nodes[0];