Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix editor crash issues #55

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading