improve asc_scene_node_allocate_data()

Thu, 17 Jul 2025 19:50:34 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 17 Jul 2025 19:50:34 +0200
changeset 210
3021616e5772
parent 209
90fc22696e94
child 211
f181205da2c9

improve asc_scene_node_allocate_data()

src/ascension/scene_node.h file | annotate | diff | comparison | revisions
src/scene_node.c file | annotate | diff | comparison | revisions
--- a/src/ascension/scene_node.h	Thu Jul 17 19:45:44 2025 +0200
+++ b/src/ascension/scene_node.h	Thu Jul 17 19:50:34 2025 +0200
@@ -227,7 +227,16 @@
 
 void asc_scene_node_update_transform(AscSceneNode *node);
 
-void asc_scene_node_allocate_data(AscSceneNode *node, size_t n);
+/**
+ * Allocates user data for the specified node.
+ *
+ * Also registers a corresponding free-function.
+ *
+ * @param node the node
+ * @param n the size of the user data
+ * @return the user data pointer
+ */
+void *asc_scene_node_allocate_data(AscSceneNode *node, size_t n);
 
 /**
  * This is the z-position a simple 2D element should have to allow
--- a/src/scene_node.c	Thu Jul 17 19:45:44 2025 +0200
+++ b/src/scene_node.c	Thu Jul 17 19:50:34 2025 +0200
@@ -214,9 +214,9 @@
     }
 }
 
-void asc_scene_node_allocate_data(AscSceneNode *node, size_t n) {
+void *asc_scene_node_allocate_data(AscSceneNode *node, size_t n) {
     if (node->user_data != NULL) {
-        asc_dprintf("WARNING: Node %"CX_PRIstr" already has user data!", CX_SFMT(node->name));
+        asc_wprintf("Node %"CX_PRIstr" already has user data which is now destroyed!", CX_SFMT(node->name));
         if (node->user_data_free_func != NULL) {
             node->user_data_free_func((void*)node->user_data_allocator, node->user_data);
         }
@@ -224,4 +224,5 @@
     node->user_data = cxZallocDefault(n);
     node->user_data_allocator = cxDefaultAllocator;
     node->user_data_free_func = (cx_destructor_func2) cxFree;
+    return node->user_data;
 }
\ No newline at end of file

mercurial