From 10effc3971424d97e41bb4aab65a282d99b5496d Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 8 Jan 2022 14:11:08 +0100 Subject: [PATCH] Delete children Nodes in Node's destructor. Also delet the tree in NodeTree's destructor. --- core/nodes/node.cpp | 5 +++++ core/nodes/node_tree.cpp | 15 ++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/nodes/node.cpp b/core/nodes/node.cpp index e97d3e8..8e4790f 100644 --- a/core/nodes/node.cpp +++ b/core/nodes/node.cpp @@ -110,4 +110,9 @@ Node::Node() : } Node::~Node() { + for (int i = 0; i < _children.size(); ++i) { + delete _children[i]; + } + + _children.clear(); } \ No newline at end of file diff --git a/core/nodes/node_tree.cpp b/core/nodes/node_tree.cpp index ac70cdc..65224ca 100644 --- a/core/nodes/node_tree.cpp +++ b/core/nodes/node_tree.cpp @@ -8,9 +8,9 @@ Node *NodeTree::get_root() { } void NodeTree::set_root(Node *root) { - if (_root_node) { - _root_node->set_tree(nullptr); - } + if (_root_node) { + _root_node->set_tree(nullptr); + } _root_node = root; @@ -20,11 +20,16 @@ void NodeTree::set_root(Node *root) { } void NodeTree::send_update(float delta) { - //todo + // todo } -NodeTree::NodeTree() : Object() { +NodeTree::NodeTree() : + Object() { } NodeTree::~NodeTree() { + if (_root_node) { + delete _root_node; + _root_node == nullptr; + } } \ No newline at end of file