diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index c57c59b8..bbe47c48 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -165,9 +165,12 @@ public: } \ \ static void *___binding_create_callback(void *p_token, void *p_instance) { \ - return memnew(m_class((GodotObject *)p_instance)); \ + /* Do not call memnew here, we don't want the postinitializer to be called */ \ + return new ("") m_class((GodotObject *)p_instance); \ } \ static void ___binding_free_callback(void *p_token, void *p_instance, void *p_binding) { \ + /* Explicitly call the deconstructor to ensure proper lifecycle for non-trivial members */ \ + reinterpret_cast(p_binding)->~m_class(); \ Memory::free_static(reinterpret_cast(p_binding)); \ } \ static GDNativeBool ___binding_reference_callback(void *p_token, void *p_instance, GDNativeBool p_reference) { \