From 6d419069b228fef99a70a8208b00cd018fa5b062 Mon Sep 17 00:00:00 2001 From: somebody_master Date: Sun, 11 Jun 2023 23:34:55 +0200 Subject: [PATCH] Add test for memory alocation Signed-off-by: somebody_master --- gdextension/include/test.hpp | 2 ++ gdextension/src/test.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/gdextension/include/test.hpp b/gdextension/include/test.hpp index 59993e4..9139e44 100644 --- a/gdextension/include/test.hpp +++ b/gdextension/include/test.hpp @@ -32,6 +32,8 @@ public: Ref get_tex_value(); void set_tex_value(Ref tex); + void start(); }; #endif + diff --git a/gdextension/src/test.cpp b/gdextension/src/test.cpp index a532d3b..912c646 100644 --- a/gdextension/src/test.cpp +++ b/gdextension/src/test.cpp @@ -19,6 +19,7 @@ void Test::_bind_methods() { ClassDB::bind_method(D_METHOD("get_tex_value"), &Test::get_tex_value); ClassDB::bind_method(D_METHOD("set_tex_value", "tex"), &Test::set_tex_value); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tex_value", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_tex_value", "get_tex_value"); + ClassDB::bind_method(D_METHOD("start"), &Test::start); } int Test::get_i_value() { @@ -52,3 +53,20 @@ Ref Test::get_tex_value() { void Test::set_tex_value(Ref tex) { tex_value = tex; } + +void Test::start() { + Node3D *node3d = memnew_arr(Node3D, 100); + + uint64_t *i = (uint64_t *)memalloc(sizeof(uint64_t)); + + uint64_t *node3d_size = (uint64_t *)node3d - 1; + + for (*i = 0; *i < *node3d_size; *i = *i + 1) { + UtilityFunctions::print(&node3d[*i]); + } + + UtilityFunctions::print(*node3d_size); + memdelete_arr(node3d); + memdelete(i); +} +