Skip to content

ScriptLanguageExtension methods can be called from multiple threads #556

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

Closed
Tracked by #713
TitanNano opened this issue Jan 7, 2024 · 4 comments · Fixed by #736
Closed
Tracked by #713

ScriptLanguageExtension methods can be called from multiple threads #556

TitanNano opened this issue Jan 7, 2024 · 4 comments · Fixed by #736
Labels
bug c: engine Godot classes (nodes, resources, ...) c: threads Related to multithreading in Godot

Comments

@TitanNano
Copy link
Contributor

I have encountered this while doing reimports of some assets.

The method ScriptLanguageExtension::frame will be called for every frame in the main loop. In parallel, the engine might call ScriptLanguageExtension::handles_global_class_type from the import thread, which will cause a panic as frame is &mut self.


The quickest workaround is to not implement ScriptLanguageExtension::frame.

@Bromeon Bromeon added bug c: engine Godot classes (nodes, resources, ...) labels Jan 7, 2024
@Bromeon
Copy link
Member

Bromeon commented Jan 7, 2024

The method ScriptLanguageExtension::frame will be called for every frame in the main loop. In parallel, the engine might call ScriptLanguageExtension::handles_global_class_type from the import thread, which will cause a panic as frame is &mut self.

Or maybe expose it without binding &mut self, similar to #[func(gd_self)] in other places?

@TitanNano
Copy link
Contributor Author

@Bromeon this is certainly an option but if someone wants to perform mutable operations in fn frame() it would still panic in certain situations due to another thread holding an immutable reference.

I think (at least with experimental-threads) access to the class instance storage should block instead of panic.

@Bromeon
Copy link
Member

Bromeon commented May 14, 2024

@TitanNano What's the situation around this after recent SiMut changes?

@TitanNano
Copy link
Contributor Author

@Bromeon unfortunately the changes to ScriptInstance are completely unrelated to this.

Godot (particularly the editor) accesses ScriptLanguage singletons across multiple threads. Since GdCell panics on the second mutable borrow, this is an issue. It would be more ergonomic if GdCell would block the other thread until it becomes available instead of panicking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug c: engine Godot classes (nodes, resources, ...) c: threads Related to multithreading in Godot
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants