Search Unity

Exception: Cannot increment reference count on operation

Discussion in 'Addressables' started by SviperSniper, Oct 16, 2019.

Thread Status:
Not open for further replies.
  1. SviperSniper

    SviperSniper

    Joined:
    Mar 1, 2017
    Posts:
    37
    Hey,
    I receive the following exception from Addressables when using the InstantiateAsync method of an AssetReference:
    I load skins of characters in the menu scene. When a match is started, all skins are unloaded as well as the scene. The loading scene than loads the skins for the match in a coroutine. Randomly the exception is thrown while loading.

    Is this a known bug?
    Thanks for your help!
     
  2. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Hey @SviperSniper, this isn't a known issue as far as I'm aware. My first instinct is to think it may be an issue with the cached async operations. Would it be possible for you to provide a little more information? Specifically how are you loading skins on your main menu scene and how are you loading them again when a match starts?

    If you have a small project that reproduces the issue consistently that would also be a massive help.

    Edit: I should mention, if you have a project you don't mind sharing but don't want to post it on the forums you're welcome to file a bug with Unity and post the case number in this thread so I can look it up.
     
    Last edited: Oct 17, 2019
  3. SviperSniper

    SviperSniper

    Joined:
    Mar 1, 2017
    Posts:
    37
    Hi David,
    thanks for your reply.

    We will try to provide a small project as soon as we can but it is probably not that easy to reproduce since it is not happening 100% of the time.

    We are actually seeing quite a few different kinds of exceptions in our crash reporting tool which all seem to be related to the same issue:

    Any help would be greatly appreciated!
    Best regards
     
  4. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    So, the "Attempting to use an invalid operation handle" is an error I've seen recently. It had to do with a race condition we were encountering on WebGL after bundles had been downloaded and cached and a user attempted to reload them.

    I should have asked before, what platform are you seeing these on? Also what version of the package are you using?
     
  5. SviperSniper

    SviperSniper

    Joined:
    Mar 1, 2017
    Posts:
    37
    We receive this exceptions on Android and iOS.
    The Unity version is 2019.2.9f1 and the Addressables Version is 1.2.4.
    We only have local asset bundles :)
     
  6. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    I see, so the issue wasn't so much "cached" bundles as it was WebRequestOperations finishing immediately and Addressables is attempting to use the op handle to set a progress callback afterwards. Since your bundles are local it could still be hitting the same condition.

    If that is the case it should be fixed in a coming release. You can either check the release when in comes out in the next week or two and report back if you're still having the problem or you can change some lines in the Resource Providers

    In AssetBundleProvider.cs and BundledAssetProvider.cs you'll see in Start(ProvideHandle provideHandle) there should be a line towards the bottom that should look like either provideHandle.SetProgressCallback(ProgressCallback); or provideHandle.SetProgressCallback(PercentComplete); Try moving these up. For AssetBundleProvider move the line just above the BeginOperation() call. For BundledAssetProvider just move that line to be the first line of the Start method.

    If you're using Virtual mode, the LegacyResourceProvider, or the TextDataProvider for anything you may need to do something similar in VirtualAssetBundleProvider, LegacyResoucesProvider, or TextDataProvider respectively.

    If none of that helps just submit a bug with Unity (providing a repro project if you can) and post the case number in this thread so we can see what's going on.
     
  7. SviperSniper

    SviperSniper

    Joined:
    Mar 1, 2017
    Posts:
    37
  8. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Hmm.. I'm not familiar with that issue. Since it isn't consistently reproducible that makes it tricky to track down. If you're ever able to get a consistent project that reproduces the issue please send it our way so we can help.

    I'll definitely keep an eye out for this issue on our end and see what can be done. Have you already filed a bug with Unity about this? That'll be a lot of help to us in keeping up with the status of this issue.
     
  9. SviperSniper

    SviperSniper

    Joined:
    Mar 1, 2017
    Posts:
    37
    There is no bug ticket yet. I will try to collect more information and will create a ticket if the issue persists.
    Thanks again for your help, David!
     
    davidla_unity likes this.
  10. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Thank you!
     
  11. SXtheOne

    SXtheOne

    Joined:
    Sep 5, 2018
    Posts:
    21
    Hi!

    I have a very similar bug. Here is a small test project. Unity 2019.3.0f3, Addressables 1.6.0. Simply setup a localhost to reach the addressables (I used python -m http.server but that shouldn't be a problem) and start the project in Unity Editor. I tried with setting the Editor to Windows platform and using the 'Use existing build' Playmode script for the addressables. After 10-15 clicks randomly on the buttons the error appeared and all the clicks gave the same error after that.

    Here is the zip of the project (Unity 2019.3.0f3):
    https://drive.google.com/file/d/1AklENGZwLIMMNl_S3g4xtoVRsdOPXo2I/view?usp=sharing

    And the error:
    Code (CSharp):
    1. Exception: Cannot increment reference count on operation UnityEngine.ResourceManagement.AsyncOperations.ProviderOperation`1[UnityEngine.ResourceManagement.ResourceProviders.IAssetBundleResource], result='', status='Succeeded' because it has already been destroyed
    2. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].IncrementReferenceCount () (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:130)
    3. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].Start (UnityEngine.ResourceManagement.ResourceManager rm, UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle dependency, DelegateList`1[T] updateCallbacks) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:398)
    4. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].UnityEngine.ResourceManagement.AsyncOperations.IAsyncOperation.Start (UnityEngine.ResourceManagement.ResourceManager rm, UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle dependency, DelegateList`1[T] updateCallbacks) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:471)
    5. UnityEngine.ResourceManagement.ResourceManager.StartOperation (UnityEngine.ResourceManagement.AsyncOperations.IAsyncOperation operation, UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle dependency) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/ResourceManager.cs:413)
    6. UnityEngine.ResourceManagement.ResourceManager.ProvideResource (UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation location, System.Type desiredType) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/ResourceManager.cs:376)
    7. UnityEngine.ResourceManagement.ResourceManager.ProvideResourceGroupCached (System.Collections.Generic.IList`1[T] locations, System.Int32 groupHash, System.Type desiredType, System.Action`1[T] callback) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/ResourceManager.cs:564)
    8. UnityEngine.ResourceManagement.ResourceManager.ProvideResource (UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation location, System.Type desiredType) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/ResourceManager.cs:370)
    9. UnityEngine.ResourceManagement.ResourceManager.ProvideResource[TObject] (UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation location) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/ResourceManager.cs:393)
    10. UnityEngine.AddressableAssets.AddressablesImpl.LoadAssetAsync[TObject] (System.Object key) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/AddressablesImpl.cs:455)
    11. UnityEngine.AddressableAssets.Addressables.LoadAssetAsync[TObject] (System.Object key) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/Addressables.cs:304)
    12. LoadOperation.Load (UnityEngine.AddressableAssets.AssetReference addressableAssetPrefab, System.Action`1[T] DoAfterLoadCompleted) (at Assets/Scripts/AddressablePrefabLoader.cs:80)
    13. AddressablePrefabLoader.Instantiate (UnityEngine.AddressableAssets.AssetReference addressableAssetPrefab, UnityEngine.Transform parent) (at Assets/Scripts/AddressablePrefabLoader.cs:31)
    14. LoaderTest.Load (System.Int32 idx) (at Assets/Scripts/LoaderTest.cs:14)
    15. UnityEngine.Events.InvokableCall`1[T1].Invoke (T1 args0) (at <7d22f8e71133418c87c7b26ea181f3e3>:0)
    16. UnityEngine.Events.CachedInvokableCall`1[T].Invoke (System.Object[] args) (at <7d22f8e71133418c87c7b26ea181f3e3>:0)
    17. UnityEngine.Events.UnityEvent.Invoke () (at <7d22f8e71133418c87c7b26ea181f3e3>:0)
    18. UnityEngine.UI.Button.Press () (at E:/gamedev/Unity_installs/2019.3.0f3/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:68)
    19. UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at E:/gamedev/Unity_installs/2019.3.0f3/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:110)
    20. UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at E:/gamedev/Unity_installs/2019.3.0f3/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50)
    21. UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at E:/gamedev/Unity_installs/2019.3.0f3/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)
    22. UnityEngine.EventSystems.EventSystem:Update() (at E:/gamedev/Unity_installs/2019.3.0f3/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)
     
  12. SXtheOne

    SXtheOne

    Joined:
    Sep 5, 2018
    Posts:
    21
    @DavidUnity3d Sorry to bother you but could you please check this out? The fixes you mentioned are already in 1.6.0 but the problem exists (see my previous post with test project included). Thanks!
     
  13. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Hey @SXtheOne yeah we're looking into it. I'll make a note of your project. Thanks for posting that.
     
    SXtheOne likes this.
Thread Status:
Not open for further replies.