InvalidOperationException appears when selecting current locale

Hello everyone,

I try to set locale in GameManager awake method, here is my code:

private static IEnumerator ChangeLocale()
        {
            yield return LocalizationSettings.InitializationOperation;
            _lang = PlayerPrefs.GetString("lang", _lang);
            Locale locale = LocalizationSettings.AvailableLocales.GetLocale(_lang);
            Locale selectedLocale = LocalizationSettings.SelectedLocale;
            if (!selectedLocale.LocaleName.Equals(locale.LocaleName))
            {
                Debug.Log("Change");
                LocalizationSettings.SelectedLocale = locale;
                // PlayerPrefs.SetString("lang", "");
            }
        }
protected override void Awake()
        {
            base.Awake();
            StartCoroutine(ChangeLocale());

...
}

I see that locale has changed:

but my game is crashed with this exception:

InvalidOperationException: Trying to release an object that has already been released to the pool.
UnityEngine.Pool.ObjectPool`1[T].Release (T element) (at /Users/bokken/buildslave/unity/build/Runtime/Export/ObjectPool/ObjectPools.cs:99)
UnityEngine.Pool.GenericPool`1[T].Release (T toRelease) (at /Users/bokken/buildslave/unity/build/Runtime/Export/ObjectPool/GenericPool.cs:30)
UnityEngine.Localization.Operations.GetLocalizedStringOperation.Destroy () (at Library/PackageCache/com.unity.localization@1.4.2/Runtime/Operations/GetLocalizedStringOperation.cs:88)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].DecrementReferenceCount () (at Library/PackageCache/com.unity.addressables@1.20.5/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:229)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].UnityEngine.ResourceManagement.AsyncOperations.IAsyncOperation.DecrementReferenceCount () (at Library/PackageCache/com.unity.addressables@1.20.5/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:589)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle.Release () (at Library/PackageCache/com.unity.addressables@1.20.5/Runtime/ResourceManager/AsyncOperations/AsyncOperationHandle.cs:532)
UnityEngine.ResourceManagement.ResourceManager.Release (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at Library/PackageCache/com.unity.addressables@1.20.5/Runtime/ResourceManager/ResourceManager.cs:686)
UnityEngine.AddressableAssets.AddressablesImpl.Release (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at Library/PackageCache/com.unity.addressables@1.20.5/Runtime/AddressablesImpl.cs:831)
UnityEngine.AddressableAssets.Addressables.Release (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at Library/PackageCache/com.unity.addressables@1.20.5/Runtime/Addressables.cs:1378)
UnityEngine.Localization.AddressablesInterface.ReleaseInternal (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at Library/PackageCache/com.unity.localization@1.4.2/Runtime/Addressables/AddressablesInterface.cs:82)
UnityEngine.Localization.AddressablesInterface.SafeRelease (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at Library/PackageCache/com.unity.localization@1.4.2/Runtime/Addressables/AddressablesInterface.cs:47)
UnityEngine.Localization.LocalizationBehaviour.LateUpdate () (at Library/PackageCache/com.unity.localization@1.4.2/Runtime/Utilities/LocalizationBehaviour.cs:32)

Unity version: 2021.3.11f1


Also default locale when I start the app is not Latvian.

I’m not aware of this bug. Could you please file a bug report?

I would also use the PlayerPreLocale selector instead of doing it manually. It can be added to the list of locale selectors in the localization settings.

Not sure if this is related; Same version of Unity.

I get the same error when instantiating an object as a child to a scroll view. The error only happens once when initially run and then fixes itself going forward until restart of play.

1 Like

Could you please file a bug report?

Hi all, sorry for late response, New Year… :slight_smile:

here is fix for this issue:

Regards, Alex

Hello, I am currently getting the same error when going into Playmode. I am making use of a PlayerPrefs Locale Selector. I know it is fixed when preloading all tables, but we don’t want all tables to be loaded into memory when they are not used. This problem also ensures that some GameObjectLocalizer components do not change the text to the correct language. Has anyone a solution to this problem?

Are you using the latest version 1.4.4? If it’s not visible in the package manager try changing the manifest.json file in the package folder.

Sorry yes, Could have mentioned that. I am using localization package 1.4.4 and addressables 1.21.8.
Not sure if it is related or helpful, but partially we Instantiate prefabs and add the GameObjectLocalizer component where we set the table entry references.

Could you please file a bug report so we can look into this? Unity QA: Building quality with passion