Browse Source

Merge pull request #798 from Faless/fix/4.x_no_memnew_cb

Rémi Verschelde 3 years ago
parent
commit
54e1385729
1 changed files with 4 additions and 1 deletions
  1. 4 1
      include/godot_cpp/classes/wrapped.hpp

+ 4 - 1
include/godot_cpp/classes/wrapped.hpp

@@ -165,9 +165,12 @@ public:
 	}                                                                                                              \
 	}                                                                                                              \
                                                                                                                    \
                                                                                                                    \
 	static void *___binding_create_callback(void *p_token, void *p_instance) {                                     \
 	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) {                       \
 	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<m_class *>(p_binding)->~m_class();                                                        \
 		Memory::free_static(reinterpret_cast<m_class *>(p_binding));                                               \
 		Memory::free_static(reinterpret_cast<m_class *>(p_binding));                                               \
 	}                                                                                                              \
 	}                                                                                                              \
 	static GDNativeBool ___binding_reference_callback(void *p_token, void *p_instance, GDNativeBool p_reference) { \
 	static GDNativeBool ___binding_reference_callback(void *p_token, void *p_instance, GDNativeBool p_reference) { \