summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaylily-Zeleen <daylily-zeleen@foxmail.com>2024-04-24 22:14:33 +0800
committerDaylily-Zeleen <daylily-zeleen@foxmail.com>2024-05-28 22:59:37 +0800
commit76cbc66785104756d6b37d16e8eb85dccc0497e8 (patch)
tree54797bab01c125f8eb51d98e37a747f9cbd0fceb /src
parentb697ba8896e5fd0966274f00798c55a5bfed4e74 (diff)
downloadredot-cpp-76cbc66785104756d6b37d16e8eb85dccc0497e8.tar.gz
Set instance and instance binding in Wrapped constructor.
Diffstat (limited to 'src')
-rw-r--r--src/classes/wrapped.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/classes/wrapped.cpp b/src/classes/wrapped.cpp
index 594cfef..52d4495 100644
--- a/src/classes/wrapped.cpp
+++ b/src/classes/wrapped.cpp
@@ -39,18 +39,16 @@
#include <godot_cpp/core/class_db.hpp>
namespace godot {
+thread_local const StringName *Wrapped::_constructing_extension_class_name = nullptr;
+thread_local const GDExtensionInstanceBindingCallbacks *Wrapped::_constructing_class_binding_callbacks = nullptr;
-const StringName *Wrapped::_get_extension_class_name() const {
+const StringName *Wrapped::_get_extension_class_name() {
return nullptr;
}
void Wrapped::_postinitialize() {
- const StringName *extension_class = _get_extension_class_name();
- if (extension_class) {
- godot::internal::gdextension_interface_object_set_instance(_owner, reinterpret_cast<GDExtensionConstStringNamePtr>(extension_class), this);
- }
- godot::internal::gdextension_interface_object_set_instance_binding(_owner, godot::internal::token, this, _get_bindings_callbacks());
- if (extension_class) {
+ // Only send NOTIFICATION_POSTINITIALIZE for extension classes.
+ if (_is_extension_class()) {
_notificationv(Object::NOTIFICATION_POSTINITIALIZE);
}
}
@@ -76,6 +74,19 @@ Wrapped::Wrapped(const StringName p_godot_class) {
}
#endif
_owner = godot::internal::gdextension_interface_classdb_construct_object(reinterpret_cast<GDExtensionConstStringNamePtr>(p_godot_class._native_ptr()));
+
+ if (_constructing_extension_class_name) {
+ godot::internal::gdextension_interface_object_set_instance(_owner, reinterpret_cast<GDExtensionConstStringNamePtr>(_constructing_extension_class_name), this);
+ _constructing_extension_class_name = nullptr;
+ }
+
+ if (likely(_constructing_class_binding_callbacks)) {
+ godot::internal::gdextension_interface_object_set_instance_binding(_owner, godot::internal::token, this, _constructing_class_binding_callbacks);
+ _constructing_class_binding_callbacks = nullptr;
+ } else {
+ ERR_PRINT("BUG: create a Godot Object without binding callbacks.");
+ CRASH_NOW_MSG("BUG: create a Godot Object without binding callbacks.");
+ }
}
Wrapped::Wrapped(GodotObject *p_godot_object) {