use tree iterator to free scene nodes

Mon, 26 Feb 2024 21:16:00 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 26 Feb 2024 21:16:00 +0100
changeset 31
8324037e0148
parent 30
fceda550ebcb
child 32
86468a71dd73

use tree iterator to free scene nodes

src/scene.c file | annotate | diff | comparison | revisions
--- a/src/scene.c	Thu Feb 22 22:34:50 2024 +0100
+++ b/src/scene.c	Mon Feb 26 21:16:00 2024 +0100
@@ -75,20 +75,18 @@
 void asc_scene_node_free(AscSceneNode *node) {
     if (node == NULL) return;
 
-    // TODO: replace with UCX tree visitor
-    // TODO: avoid recursion
-
-    // free the children recursively
-    while (node->children != NULL) {
-        asc_scene_node_free(node->children);
-    }
-
     // remove this node from its parent
     asc_scene_node_unlink(node);
 
-    // free the node
-    if (node->free_func != NULL) {
-        node->free_func(node);
+    // free the entire subtree
+    CxTreeIterator iter = cx_tree_iterator(node, true, child_list_off_);
+    cx_foreach(AscSceneNode*, child, iter) {
+        if (!iter.exiting) continue;
+        if (child->free_func != NULL) {
+            child->free_func(child);
+        } else {
+            free(child);
+        }
     }
 }
 

mercurial