--- a/src/scene_node.c Sat May 10 15:06:47 2025 +0200 +++ b/src/scene_node.c Sat May 10 15:42:56 2025 +0200 @@ -30,6 +30,9 @@ #include <cx/tree.h> #include <cx/linked_list.h> +#include <cx/printf.h> + +#include "ascension/error.h" static CxTreeIterator asc_scene_node_iterator( AscSceneNode *node, @@ -56,7 +59,10 @@ if (node->destroy_func != NULL) { node->destroy_func(node); } - free(node->name); + if (node->name.ptr != NULL) { + asc_dprintf("Destroy node: %"CX_PRIstr, CX_SFMT(node->name)); + cx_strfree(&node->name); + } } void asc_scene_node_free(AscSceneNode *node) { @@ -74,6 +80,35 @@ } } +void asc_scene_node_name(AscSceneNode *node, const char *name) { + free(node->name.ptr); + if (name == NULL) { + node->name.ptr = NULL; + node->name.length = 0; + } else { + node->name.ptr = strdup(name); + node->name.length = strlen(name); + } +} + +cxstring asc_scene_node_get_name(AscSceneNode *node) { + if (node->name.ptr != NULL) return cx_strcast(node->name); + + AscSceneNode *parent = node->parent; + while (parent != NULL && parent->name.ptr == NULL) { + parent = parent->parent; + } + if (parent == NULL) { + cx_sprintf(&node->name.ptr, &node->name.length, + "%"PRIuPTR " - w/o named parent", (uintptr_t)node); + } else { + cx_sprintf(&node->name.ptr, &node->name.length, + "%"PRIuPTR " - child of %"CX_PRIstr, (uintptr_t)node, CX_SFMT(parent->name)); + } + + return cx_strcast(node->name); +} + void asc_scene_node_link(AscSceneNode * restrict parent, AscSceneNode * restrict node) { cx_tree_link( parent, node,