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:
8687052--1171614--Screenshot 2022-12-26 at 13.12.49.png

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

8687052--1171617--Screenshot 2022-12-26 at 13.19.28.png
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?
https://unity.com/releases/editor/qa/bug-reporting

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.

8697552--1173846--upload_2023-1-1_10-27-12.png

1 Like

[quote=“Welfarecheck”, post:3, topic: 904281]
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.

[/quote]
Could you please file a bug report?

Hi all, sorry for late response, New Year... :)

here is fix for this issue:

8697627--1173879--Screenshot 2023-01-01 at 19.05.40.png

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?

[quote=“StickySjors”, post:6, topic: 904281]
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?
[/quote]
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? https://unity.com/releases/editor/qa/bug-reporting