@@ -216,16 +216,32 @@ pub fn auto_register_classes(init_level: InitLevel) {
216
216
// but it is much slower and doesn't guarantee that all the dependent classes will be already loaded in most cases.
217
217
register_classes_and_dyn_traits ( & mut map, init_level) ;
218
218
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
+
219
223
// Actually register all the classes.
220
224
for info in map. into_values ( ) {
221
225
#[ cfg( feature = "debug-log" ) ]
222
226
let class_name = info. class_name ;
223
227
228
+ if info. is_editor_plugin {
229
+ editor_plugins. push ( info. class_name ) ;
230
+ }
231
+
224
232
register_class_raw ( info) ;
225
233
226
234
out ! ( "Class {class_name} loaded." ) ;
227
235
}
228
236
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
+
229
245
out ! ( "All classes for level `{init_level:?}` auto-registered." ) ;
230
246
}
231
247
@@ -617,10 +633,6 @@ fn register_class_raw(mut info: ClassRegistrationInfo) {
617
633
if let Some ( register_fn) = info. user_register_fn {
618
634
( register_fn. raw ) ( & mut class_builder) ;
619
635
}
620
-
621
- if info. is_editor_plugin {
622
- unsafe { interface_fn ! ( editor_add_plugin) ( class_name. string_sys ( ) ) } ;
623
- }
624
636
}
625
637
626
638
fn validate_class_constraints ( _class : & ClassRegistrationInfo ) {
0 commit comments