diff options
| author | David Snopek <dsnopek@gmail.com> | 2024-04-09 13:40:33 -0500 |
|---|---|---|
| committer | David Snopek <dsnopek@gmail.com> | 2024-04-09 13:40:33 -0500 |
| commit | 87aec2745d1b7c7324d6e61176ce29602b8a08cb (patch) | |
| tree | 68964aaf8e4db29f96e8c64f6fa5d01f4fa621a0 /core/object | |
| parent | dd926b9132c2f755b6f310fcd0aecaa441e123c5 (diff) | |
| download | redot-engine-87aec2745d1b7c7324d6e61176ce29602b8a08cb.tar.gz | |
Fix GDExtension hot reload for classes not created via `ClassDB::instantiate()`
Diffstat (limited to 'core/object')
| -rw-r--r-- | core/object/class_db.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 80a2703c2f..7ef1ce74ed 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -182,8 +182,20 @@ public: // Construct a placeholder. Object *obj = native_parent->creation_func(); + + // ClassDB::set_object_extension_instance() won't be called for placeholders. + // We need need to make sure that all the things it would have done (even if + // done in a different way to support placeholders) will also be done here. + obj->_extension = ClassDB::get_placeholder_extension(ti->name); obj->_extension_instance = memnew(PlaceholderExtensionInstance(ti->name)); + +#ifdef TOOLS_ENABLED + if (obj->_extension->track_instance) { + obj->_extension->track_instance(obj->_extension->tracking_userdata, obj); + } +#endif + return obj; } @@ -506,14 +518,7 @@ Object *ClassDB::_instantiate_internal(const StringName &p_class, bool p_require extension = get_placeholder_extension(ti->name); } #endif - Object *obj = (Object *)extension->create_instance(extension->class_userdata); - -#ifdef TOOLS_ENABLED - if (extension->track_instance) { - extension->track_instance(extension->tracking_userdata, obj); - } -#endif - return obj; + return (Object *)extension->create_instance(extension->class_userdata); } else { #ifdef TOOLS_ENABLED if (!p_require_real_class && ti->is_runtime && Engine::get_singleton()->is_editor_hint()) { @@ -638,6 +643,12 @@ void ClassDB::set_object_extension_instance(Object *p_object, const StringName & p_object->_extension = ti->gdextension; p_object->_extension_instance = p_instance; + +#ifdef TOOLS_ENABLED + if (p_object->_extension->track_instance) { + p_object->_extension->track_instance(p_object->_extension->tracking_userdata, p_object); + } +#endif } bool ClassDB::can_instantiate(const StringName &p_class) { |
