Search Unity

Bug InvalidOperationException appears when selecting current locale

Discussion in 'Localization Tools' started by Dailyalex, Dec 26, 2022.

  1. Dailyalex

    Dailyalex

    Joined:
    Oct 21, 2015
    Posts:
    4
    Hello everyone,

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

    Code (CSharp):
    1. private static IEnumerator ChangeLocale()
    2.         {
    3.             yield return LocalizationSettings.InitializationOperation;
    4.             _lang = PlayerPrefs.GetString("lang", _lang);
    5.             Locale locale = LocalizationSettings.AvailableLocales.GetLocale(_lang);
    6.             Locale selectedLocale = LocalizationSettings.SelectedLocale;
    7.             if (!selectedLocale.LocaleName.Equals(locale.LocaleName))
    8.             {
    9.                 Debug.Log("Change");
    10.                 LocalizationSettings.SelectedLocale = locale;
    11.                 // PlayerPrefs.SetString("lang", "");
    12.             }
    13.         }
    Code (CSharp):
    1. protected override void Awake()
    2.         {
    3.             base.Awake();
    4.             StartCoroutine(ChangeLocale());
    5.  
    6. ...
    7. }
    I see that locale has changed:
    Screenshot 2022-12-26 at 13.12.49.png

    but my game is crashed with this exception:

    Code (CSharp):
    1. InvalidOperationException: Trying to release an object that has already been released to the pool.
    2. UnityEngine.Pool.ObjectPool`1[T].Release (T element) (at /Users/bokken/buildslave/unity/build/Runtime/Export/ObjectPool/ObjectPools.cs:99)
    3. UnityEngine.Pool.GenericPool`1[T].Release (T toRelease) (at /Users/bokken/buildslave/unity/build/Runtime/Export/ObjectPool/GenericPool.cs:30)
    4. UnityEngine.Localization.Operations.GetLocalizedStringOperation.Destroy () (at Library/PackageCache/com.unity.localization@1.4.2/Runtime/Operations/GetLocalizedStringOperation.cs:88)
    5. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].DecrementReferenceCount () (at Library/PackageCache/com.unity.addressables@1.20.5/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:229)
    6. 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)
    7. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle.Release () (at Library/PackageCache/com.unity.addressables@1.20.5/Runtime/ResourceManager/AsyncOperations/AsyncOperationHandle.cs:532)
    8. UnityEngine.ResourceManagement.ResourceManager.Release (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at Library/PackageCache/com.unity.addressables@1.20.5/Runtime/ResourceManager/ResourceManager.cs:686)
    9. UnityEngine.AddressableAssets.AddressablesImpl.Release (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at Library/PackageCache/com.unity.addressables@1.20.5/Runtime/AddressablesImpl.cs:831)
    10. UnityEngine.AddressableAssets.Addressables.Release (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at Library/PackageCache/com.unity.addressables@1.20.5/Runtime/Addressables.cs:1378)
    11. UnityEngine.Localization.AddressablesInterface.ReleaseInternal (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at Library/PackageCache/com.unity.localization@1.4.2/Runtime/Addressables/AddressablesInterface.cs:82)
    12. UnityEngine.Localization.AddressablesInterface.SafeRelease (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle handle) (at Library/PackageCache/com.unity.localization@1.4.2/Runtime/Addressables/AddressablesInterface.cs:47)
    13. UnityEngine.Localization.LocalizationBehaviour.LateUpdate () (at Library/PackageCache/com.unity.localization@1.4.2/Runtime/Utilities/LocalizationBehaviour.cs:32)
    Unity version: 2021.3.11f1

    Screenshot 2022-12-26 at 13.19.28.png
    Also default locale when I start the app is not Latvian.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    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.
     
  3. Welfarecheck

    Welfarecheck

    Joined:
    Jun 14, 2020
    Posts:
    120
    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.

    upload_2023-1-1_10-27-12.png
     
    RunningStone likes this.
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    Could you please file a bug report?
     
  5. Dailyalex

    Dailyalex

    Joined:
    Oct 21, 2015
    Posts:
    4
    Hi all, sorry for late response, New Year... :)

    here is fix for this issue:

    Screenshot 2023-01-01 at 19.05.40.png

    Regards, Alex
     
  6. StickySjors

    StickySjors

    Joined:
    Nov 16, 2022
    Posts:
    2
    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?
     
  7. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    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.
     
  8. StickySjors

    StickySjors

    Joined:
    Nov 16, 2022
    Posts:
    2
    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.
     
  9. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281