Skip to content

Commit ced4c42

Browse files
authored
Merge pull request #55 from RedMser/godot-rust-0.2-stable
Fix editor crash issues
2 parents f0bf18e + c816a85 commit ced4c42

File tree

6 files changed

+37
-25
lines changed

6 files changed

+37
-25
lines changed

godot/default/addons/godot-fluent-translation/godot-fluent-translation.gdextension

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[configuration]
22
entry_symbol = "gdext_rust_init"
33
compatibility_minimum = 4.3
4-
reloadable = true
54

65
[libraries]
76
linux.debug.x86_64 = "res://../../rust/target/debug/libgodot_fluent_translation.so"

godot/forked/addons/godot-fluent-translation/godot-fluent-translation.gdextension

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[configuration]
22
entry_symbol = "gdext_rust_init"
33
compatibility_minimum = 4.3
4-
reloadable = true
54

65
[libraries]
76
linux.debug.x86_64 = "res://../../rust/target/debug/libgodot_fluent_translation.so"

rust/Cargo.lock

Lines changed: 23 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ crate-type = ["cdylib"] # Compile this crate to a dynamic C library.
1818
constcat = "0.5.0"
1919
fluent = { git = "https://github.com/projectfluent/fluent-rs", branch = "main" }
2020
fluent-syntax = { git = "https://github.com/projectfluent/fluent-rs", branch = "main" }
21-
godot = { git = "https://github.com/godot-rust/gdext", branch = "master", features = ["register-docs", "lazy-function-tables"] }
21+
godot = { version = "0.2.1", features = ["register-docs", "lazy-function-tables"] }
2222
itertools = "0.13.0"
2323
unic-langid = "0.9.4"

rust/src/fluent/global.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
use godot::prelude::*;
2-
use godot::classes::ResourceLoader;
2+
use godot::classes::{Engine, ResourceLoader};
33

44
use super::ResourceFormatLoaderFluent;
55

66
/// Singleton for handling Fluent Translation. For internal use only.
77
#[derive(GodotClass)]
88
#[class(base=Object, init)]
99
pub struct FluentI18nSingleton {
10-
loader: Gd<ResourceFormatLoaderFluent>,
10+
loader: Option<Gd<ResourceFormatLoaderFluent>>,
1111
}
1212

1313
impl FluentI18nSingleton {
1414
pub(crate) const SINGLETON_NAME: &'static str = "FluentI18nSingleton";
1515

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+
}
1822
}
1923

2024
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+
}
2228
}
2329
}

rust/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ unsafe impl ExtensionLibrary for FluentI18n {
2525
if level == InitLevel::Scene {
2626
project_settings::register();
2727

28-
let singleton = FluentI18nSingleton::new_alloc();
29-
singleton.bind().register();
28+
let mut singleton = FluentI18nSingleton::new_alloc();
29+
singleton.bind_mut().register();
3030

3131
Engine::singleton()
3232
.register_singleton(FluentI18nSingleton::SINGLETON_NAME, &singleton);

0 commit comments

Comments
 (0)