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

Support loading of translations on threads #78747

Merged
merged 1 commit into from
Jul 26, 2023

Conversation

RandomShaper
Copy link
Member

@RandomShaper RandomShaper commented Jun 27, 2023

Resources can safely do deferred calls from threads in the context of resource loading. The ResourceLoader has a mechanism in place to make them eventually run on the main thread, safely. With this PR, the patched call can benefit from it.

That said, ideally we would have a safety net in some other layer of the engine. We are patching this call because we know that its current implementation leads to thread-unsafe calls along the call chain. In other words, this fix is a bit flimsy as it relies too much on implementation details of other classes. UPDATE: Implementation changed to move the threading concern to the resource class instead of the translation loader; I'm a bit happier with this, but none should be having to care about that, to be honest.

Fixes #78689 (but testing is needed to confirm; can anyone check?).

@RandomShaper RandomShaper added this to the 4.2 milestone Jun 27, 2023
@RandomShaper RandomShaper requested a review from a team as a code owner June 27, 2023 12:26
@akien-mga akien-mga added the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Jun 27, 2023
@Dragoncraft89
Copy link
Contributor

Can confirm that this fixes #78689 for me

@Dragoncraft89
Copy link
Contributor

I think this fix introduces a regression:

TranslationServer.add_translation(load("res://es.po"))

registers as a translation of the locale en (that's the default value)

@Dragoncraft89
Copy link
Contributor

Here's a MRP showing the regression:
translation_bug.zip

Note that this only happens when a translation is made with tr() while the set_deferred hasn't triggered yet. Therefore for GUI nodes this bug only is visible for one frame

@RandomShaper
Copy link
Member Author

I've updated the PR (including the description). Both cases should work now.

@RandomShaper
Copy link
Member Author

This one would be good for 4.2 dev builds.

@YuriSizov YuriSizov merged commit 7c20487 into godotengine:master Jul 26, 2023
@YuriSizov
Copy link
Contributor

Thanks!

@RandomShaper RandomShaper deleted the fix_trans_threading branch July 26, 2023 17:31
@YuriSizov
Copy link
Contributor

Cherry-picked for 4.1.3.

@YuriSizov YuriSizov removed the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Double free or corruption involving ResourceLoader.load_threaded_request
4 participants