Skip to content

Commit

Permalink
Merge pull request #55 from RedMser/godot-rust-0.2-stable
Browse files Browse the repository at this point in the history
Fix editor crash issues
  • Loading branch information
RedMser authored Dec 21, 2024
2 parents f0bf18e + c816a85 commit ced4c42
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[configuration]
entry_symbol = "gdext_rust_init"
compatibility_minimum = 4.3
reloadable = true

[libraries]
linux.debug.x86_64 = "res://../../rust/target/debug/libgodot_fluent_translation.so"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[configuration]
entry_symbol = "gdext_rust_init"
compatibility_minimum = 4.3
reloadable = true

[libraries]
linux.debug.x86_64 = "res://../../rust/target/debug/libgodot_fluent_translation.so"
Expand Down
38 changes: 23 additions & 15 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ crate-type = ["cdylib"] # Compile this crate to a dynamic C library.
constcat = "0.5.0"
fluent = { git = "https://github.com/projectfluent/fluent-rs", branch = "main" }
fluent-syntax = { git = "https://github.com/projectfluent/fluent-rs", branch = "main" }
godot = { git = "https://github.com/godot-rust/gdext", branch = "master", features = ["register-docs", "lazy-function-tables"] }
godot = { version = "0.2.1", features = ["register-docs", "lazy-function-tables"] }
itertools = "0.13.0"
unic-langid = "0.9.4"
16 changes: 11 additions & 5 deletions rust/src/fluent/global.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
use godot::prelude::*;
use godot::classes::ResourceLoader;
use godot::classes::{Engine, ResourceLoader};

use super::ResourceFormatLoaderFluent;

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

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

pub(crate) fn register(&self) {
ResourceLoader::singleton().add_resource_format_loader(&self.loader);
pub(crate) fn register(&mut self) {
// HACK: Resource format loader crashes editor on startup, see https://github.com/godot-rust/gdext/issues/597
if !Engine::singleton().is_editor_hint() {
self.loader = Some(ResourceFormatLoaderFluent::new_gd());
ResourceLoader::singleton().add_resource_format_loader(&self.loader.clone().unwrap());
}
}

pub(crate) fn unregister(&self) {
ResourceLoader::singleton().remove_resource_format_loader(&self.loader);
if let Some(loader) = &self.loader {
ResourceLoader::singleton().remove_resource_format_loader(loader);
}
}
}
4 changes: 2 additions & 2 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ unsafe impl ExtensionLibrary for FluentI18n {
if level == InitLevel::Scene {
project_settings::register();

let singleton = FluentI18nSingleton::new_alloc();
singleton.bind().register();
let mut singleton = FluentI18nSingleton::new_alloc();
singleton.bind_mut().register();

Engine::singleton()
.register_singleton(FluentI18nSingleton::SINGLETON_NAME, &singleton);
Expand Down

0 comments on commit ced4c42

Please sign in to comment.