From 7b93607779b6ecaf9d55c345715f6154751f2a14 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Wed, 24 Apr 2024 13:01:53 -0500 Subject: [PATCH] Fix NOTIFICATION_POSTINITIALIZE sent twice to native parent class (cherry picked from commit 06373ce1cf737a33d6a7b2b14cfe25ed729b9c48) --- include/godot_cpp/classes/wrapped.hpp | 6 ++++++ src/classes/wrapped.cpp | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index a8bd3a0..d325fed 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -76,6 +76,7 @@ protected: uint32_t plist_size = 0; void _postinitialize(); + virtual void _notificationv(int32_t p_what) {} Wrapped(const StringName p_godot_class); Wrapped(GodotObject *p_godot_object); @@ -328,6 +329,11 @@ public: _gde_binding_reference_callback, \ }; \ \ +protected: \ + virtual void _notificationv(int32_t p_what) override { \ + m_class::notification_bind(this, p_what); \ + } \ + \ private: // Don't use this for your classes, use GDCLASS() instead. diff --git a/src/classes/wrapped.cpp b/src/classes/wrapped.cpp index 8a2092c..f1b31aa 100644 --- a/src/classes/wrapped.cpp +++ b/src/classes/wrapped.cpp @@ -51,10 +51,7 @@ void Wrapped::_postinitialize() { } godot::internal::gdextension_interface_object_set_instance_binding(_owner, godot::internal::token, this, _get_bindings_callbacks()); if (extension_class) { - Object *obj = dynamic_cast(this); - if (obj) { - obj->notification(Object::NOTIFICATION_POSTINITIALIZE); - } + _notificationv(Object::NOTIFICATION_POSTINITIALIZE); } }