Skip to content

Commit b1792e5

Browse files
committed
Merge pull request #109309 from dsnopek/gdextension-startup-callback-after-reload
GDExtension: Call startup callback only after reload is fully finished
2 parents 7aa331a + 92d9227 commit b1792e5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

core/extension/gdextension_manager.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ GDExtensionManager::LoadStatus GDExtensionManager::_load_extension_internal(cons
5555
gdextension_class_icon_paths[kv.key] = kv.value;
5656
}
5757

58+
return LOAD_STATUS_OK;
59+
}
60+
61+
void GDExtensionManager::_finish_load_extension(const Ref<GDExtension> &p_extension) {
5862
#ifdef TOOLS_ENABLED
5963
// Signals that a new extension is loaded so GDScript can register new class names.
6064
emit_signal("extension_loaded", p_extension);
@@ -67,8 +71,6 @@ GDExtensionManager::LoadStatus GDExtensionManager::_load_extension_internal(cons
6771
p_extension->startup_callback();
6872
}
6973
}
70-
71-
return LOAD_STATUS_OK;
7274
}
7375

7476
GDExtensionManager::LoadStatus GDExtensionManager::_unload_extension_internal(const Ref<GDExtension> &p_extension) {
@@ -134,6 +136,8 @@ GDExtensionManager::LoadStatus GDExtensionManager::load_extension_with_loader(co
134136
return status;
135137
}
136138

139+
_finish_load_extension(extension);
140+
137141
extension->set_path(p_path);
138142
gdextension_map[p_path] = extension;
139143
return LOAD_STATUS_OK;
@@ -186,6 +190,10 @@ GDExtensionManager::LoadStatus GDExtensionManager::reload_extension(const String
186190

187191
extension->finish_reload();
188192

193+
// Needs to come after reload is fully finished, so all objects using
194+
// extension classes are in a consistent state.
195+
_finish_load_extension(extension);
196+
189197
return LOAD_STATUS_OK;
190198
#endif
191199
}

core/extension/gdextension_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class GDExtensionManager : public Object {
5757

5858
private:
5959
LoadStatus _load_extension_internal(const Ref<GDExtension> &p_extension, bool p_first_load);
60+
void _finish_load_extension(const Ref<GDExtension> &p_extension);
6061
LoadStatus _unload_extension_internal(const Ref<GDExtension> &p_extension);
6162

6263
#ifdef TOOLS_ENABLED

0 commit comments

Comments
 (0)