File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 1
1
use godot:: prelude:: * ;
2
- use godot:: classes:: ResourceLoader ;
2
+ use godot:: classes:: { Engine , ResourceLoader } ;
3
3
4
4
use super :: ResourceFormatLoaderFluent ;
5
5
6
6
/// Singleton for handling Fluent Translation. For internal use only.
7
7
#[ derive( GodotClass ) ]
8
8
#[ class( base=Object , init) ]
9
9
pub struct FluentI18nSingleton {
10
- loader : Gd < ResourceFormatLoaderFluent > ,
10
+ loader : Option < Gd < ResourceFormatLoaderFluent > > ,
11
11
}
12
12
13
13
impl FluentI18nSingleton {
14
14
pub ( crate ) const SINGLETON_NAME : & ' static str = "FluentI18nSingleton" ;
15
15
16
- pub ( crate ) fn register ( & self ) {
17
- ResourceLoader :: singleton ( ) . add_resource_format_loader ( & self . loader ) ;
16
+ pub ( crate ) fn register ( & mut self ) {
17
+ // HACK: Resource format loader crashes editor on startup, see https://github.com/godot-rust/gdext/issues/597
18
+ if !Engine :: singleton ( ) . is_editor_hint ( ) {
19
+ self . loader = Some ( ResourceFormatLoaderFluent :: new_gd ( ) ) ;
20
+ ResourceLoader :: singleton ( ) . add_resource_format_loader ( & self . loader . clone ( ) . unwrap ( ) ) ;
21
+ }
18
22
}
19
23
20
24
pub ( crate ) fn unregister ( & self ) {
21
- ResourceLoader :: singleton ( ) . remove_resource_format_loader ( & self . loader ) ;
25
+ if let Some ( loader) = & self . loader {
26
+ ResourceLoader :: singleton ( ) . remove_resource_format_loader ( loader) ;
27
+ }
22
28
}
23
29
}
Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ unsafe impl ExtensionLibrary for FluentI18n {
25
25
if level == InitLevel :: Scene {
26
26
project_settings:: register ( ) ;
27
27
28
- let singleton = FluentI18nSingleton :: new_alloc ( ) ;
29
- singleton. bind ( ) . register ( ) ;
28
+ let mut singleton = FluentI18nSingleton :: new_alloc ( ) ;
29
+ singleton. bind_mut ( ) . register ( ) ;
30
30
31
31
Engine :: singleton ( )
32
32
. register_singleton ( FluentI18nSingleton :: SINGLETON_NAME , & singleton) ;
You can’t perform that action at this time.
0 commit comments