Skip to content

Commit b0be794

Browse files
authored
Merge pull request #1138 from Yarwin/fix-editor-plugin-crash
Fix crash related to adding EditorPlugin to the editor before all the classes are registered.
2 parents 3470b50 + 9ed5cfc commit b0be794

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

godot-core/src/registry/class.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,32 @@ pub fn auto_register_classes(init_level: InitLevel) {
216216
// but it is much slower and doesn't guarantee that all the dependent classes will be already loaded in most cases.
217217
register_classes_and_dyn_traits(&mut map, init_level);
218218

219+
// Editor plugins should be added to the editor AFTER all the classes has been registered.
220+
// Adding EditorPlugin to the Editor before registering all the classes it depends on might result in crash.
221+
let mut editor_plugins: Vec<ClassName> = Vec::new();
222+
219223
// Actually register all the classes.
220224
for info in map.into_values() {
221225
#[cfg(feature = "debug-log")]
222226
let class_name = info.class_name;
223227

228+
if info.is_editor_plugin {
229+
editor_plugins.push(info.class_name);
230+
}
231+
224232
register_class_raw(info);
225233

226234
out!("Class {class_name} loaded.");
227235
}
228236

237+
// Will imminently add given class to the editor.
238+
// It is expected and beneficial behaviour while we load library for the first time
239+
// but (for now) might lead to some issues during hot reload.
240+
// See also: (https://github.com/godot-rust/gdext/issues/1132)
241+
for editor_plugin_class_name in editor_plugins {
242+
unsafe { interface_fn!(editor_add_plugin)(editor_plugin_class_name.string_sys()) };
243+
}
244+
229245
out!("All classes for level `{init_level:?}` auto-registered.");
230246
}
231247

@@ -617,10 +633,6 @@ fn register_class_raw(mut info: ClassRegistrationInfo) {
617633
if let Some(register_fn) = info.user_register_fn {
618634
(register_fn.raw)(&mut class_builder);
619635
}
620-
621-
if info.is_editor_plugin {
622-
unsafe { interface_fn!(editor_add_plugin)(class_name.string_sys()) };
623-
}
624636
}
625637

626638
fn validate_class_constraints(_class: &ClassRegistrationInfo) {

0 commit comments

Comments
 (0)