Exception: Cannot increment reference count on operation

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!

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.

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

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?

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 :slight_smile:

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.

These are awesome news!
We will wait for the update and will inform you / create a bug ticket if the issue persists.

Thanks a lot for your help!

I have another question regarding this ticket:

Do you have any idea how to approach this?
Best regards

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.

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!

1 Like

Thank you!

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):

And the error:

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
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].IncrementReferenceCount () (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:130)
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)
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)
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)
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)
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)
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)
UnityEngine.ResourceManagement.ResourceManager.ProvideResource[TObject] (UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation location) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/ResourceManager/ResourceManager.cs:393)
UnityEngine.AddressableAssets.AddressablesImpl.LoadAssetAsync[TObject] (System.Object key) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/AddressablesImpl.cs:455)
UnityEngine.AddressableAssets.Addressables.LoadAssetAsync[TObject] (System.Object key) (at Library/PackageCache/com.unity.addressables@1.6.0/Runtime/Addressables.cs:304)
LoadOperation.Load (UnityEngine.AddressableAssets.AssetReference addressableAssetPrefab, System.Action`1[T] DoAfterLoadCompleted) (at Assets/Scripts/AddressablePrefabLoader.cs:80)
AddressablePrefabLoader.Instantiate (UnityEngine.AddressableAssets.AssetReference addressableAssetPrefab, UnityEngine.Transform parent) (at Assets/Scripts/AddressablePrefabLoader.cs:31)
LoaderTest.Load (System.Int32 idx) (at Assets/Scripts/LoaderTest.cs:14)
UnityEngine.Events.InvokableCall`1[T1].Invoke (T1 args0) (at <7d22f8e71133418c87c7b26ea181f3e3>:0)
UnityEngine.Events.CachedInvokableCall`1[T].Invoke (System.Object[] args) (at <7d22f8e71133418c87c7b26ea181f3e3>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <7d22f8e71133418c87c7b26ea181f3e3>:0)
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)
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)
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)
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)
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)

@davidla_unity 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!

Hey @SXtheOne yeah we’re looking into it. I’ll make a note of your project. Thanks for posting that.

1 Like