LocalizedString.GetLocalizedString sometimes causes freeze (race-condition in Addressables?)

My game randomly freezes during LocalizedString.GetLocalizedString. It’s probably a race-condition inside the Addressables code.

Unfortunately, it occurs in our production project only. I’m unable to reproduce it in a smaller test project. But I wanted to post it here nonetheless, perhaps you have an idea.

The very first code that’s executed in the game (added as first scene in ‘Scenes in Build’) just a light-weight loader scene and contains this code:

System.Collections.IEnumerator Start()
{
    // control how long it takes to load data asynchronously vs performance impact on the game while loading in the background.
    // at application startup and during the loading screen in general, we don't care for smooth framerate. We want the work to get done fast.
    Application.backgroundLoadingPriority = ThreadPriority.High;

    // Without initializing Addressables, the game sometimes hangs
    yield return UnityEngine.AddressableAssets.Addressables.InitializeAsync();

    // Load menu scene
    yield return SceneManager.LoadSceneAsync(k_SceneToLoad);

Loading the scene sometimes triggers the freeze, because Components in that scene call LocalizedString.GetLocalizedString.

The game is stuck here:

I added tons of yield’s to the code in a desperate attempt to workaround it. At first it looked like it would work, but you just have start the game often enough to run into the freeze again:

System.Collections.IEnumerator Start()
{
    // control how long it takes to load data asynchronously vs performance impact on the game while loading in the background.
    // at application startup and during the loading screen in general, we don't care for smooth framerate. We want the work to get done fast.
    Application.backgroundLoadingPriority = ThreadPriority.High;

    // Without initializing Addressables, the game sometimes hangs
    yield return UnityEngine.AddressableAssets.Addressables.InitializeAsync();
    yield return null; // without this the game sometimes hangs too (seems like a race condition in addressables)

    // without this the game sometimes freezes (seems like a race condition in addressables)
    yield return UnityEngine.Localization.Settings.LocalizationSettings.InitializationOperation;
    yield return null; // not sure if this yield is necessary
    yield return UnityEngine.Localization.Settings.LocalizationSettings.StringDatabase.PreloadOperation;
    yield return null; // not sure if this yield is necessary

    // Load menu scene
    yield return SceneManager.LoadSceneAsync(k_SceneToLoad);

Adding yield return LocalizationSettings slightly changed where the game is freezing. I also tried WaitForCompletion, but same problem.

Are you able to file a bug report?
I know there’s an issue with calling wait for completion inside of an addressables callback, which can be caused by the selected locale changed event, I have a fix for the selected locale changed. Have you tried updating to the latest addressables package?
It looks like something unrelated to localization.

1 Like

I wish I could. It’s our actual production project where it happens, it’s difficult.

Cool, crossing fingers it’s that problem :slight_smile:

I’m using Addressables 1.18.4 where this problem occurs. I tried Addressables 1.18.9 a few days ago, but ran in other major issues that made me revert to Addressables 1.18.4.

I suspect it’s not the wait for completion issue. That should produce an error about either an invalid index or recursion issue, depending on the addressables version.ill ask the addressables team if they have any ideas.

1 Like

Is there any way you could share your project with us so we could debug it?
Do you have any native call stacks or crash dumps that may indicate what could be locking things up?

1 Like

The next time it freezes I try to save a Visual Studio dump file.

1 Like

What platform was this? Windows Standalone?

Yes, Windows Standalone. The freeze I sent to you was in the editor with “Use existing Build” as Addressables Playmode Script setting as far as I remember.

1 Like