Coder Social home page Coder Social logo

Comments (6)

Dream-Engine-Games avatar Dream-Engine-Games commented on August 28, 2024

Having the same issue. Did you manage to fix it?

from addressables-sample.

JPerryOddGames avatar JPerryOddGames commented on August 28, 2024

We're also seeing this issue, using Addressables 1.20.5
Callstack is as follows
System.Exception: Attempting to use an invalid operation handle File "AsyncOperationHandle.cs", line 213, in get_InternalOp File "AsyncOperationHandle.cs", line 278, in get_Result File "InitializationOperation.cs", line 95, in Execute File "AsyncOperationBase.cs", line 536, in InvokeExecute File "AsyncOperationBase.cs", line 148, in <.ctor>b__35_0 File "AsyncOperationBase.cs", line 330, in add_CompletedTypeless { <lambda> } File "Generics12.cpp", line 20941, in Invoke File "Generics47.cpp", in Invoke File "AsyncOperationBase.cs", line 395, in InvokeCompletionEvent File "AsyncOperationBase.cs", line 508, in Complete File "Generics23.cpp", line 25763, in Complete File "AsyncOperationBase.cs", line 435, in Complete File "Unity.Addressables.cpp", line 9095, in Execute { <lambda> } File "Generics12.cpp", line 21097, in Invoke File "Generics47.cpp", in Invoke File "AsyncOperationBase.cs", line 395, in InvokeCompletionEvent File "AsyncOperationBase.cs", line 508, in Complete File "Unity.ResourceManager.cpp", line 35049, in CompleteIfDependenciesComplete File "GroupOperation.cs", line 228, in OnOperationCompleted File "AsyncOperationBase.cs", line 330, in add_CompletedTypeless { <lambda> } File "Generics12.cpp", line 20941, in Invoke File "Generics47.cpp", in Invoke File "AsyncOperationBase.cs", line 395, in InvokeCompletionEvent File "AsyncOperationBase.cs", line 508, in Complete File "Generics23.cpp", line 25763, in Complete File "AsyncOperationBase.cs", line 435, in Complete File "PlayAssetDeliveryInitialization.cs", line 76, in CompleteOverride File "AddressablesPlayAssetDelivery.cpp", line 4686, in DownloadCustomAssetPacksData { <lambda> }

from addressables-sample.

JPerryOddGames avatar JPerryOddGames commented on August 28, 2024

@kirstenpilla hi, do you have any idea what might cause this issue?
We're using the code from the Play Asset Delivery sample project you added, and using Unity 2020.3.13f1 with addressables 1.20.5.
The error occurs at launch every session after the PlayAssetDeliveryInitializeOperation completes. Some callback assigned to the CompletedTypeless event throws an exception, but I've struggled to find out which class/method it is. Regardless I believe it's complaining that the PlayAssetDeliveryInitializeOperation itself is invalid.
If you have any information or ideas to try, please advise, thank you!

from addressables-sample.

restush avatar restush commented on August 28, 2024

@JPerryOddGames Hello, have you solved the issue yet?
I also have same problem but using Unity 2021.3.16 with latest addresssables. I believe the problem was ProvideHandle m_ProviderInterface in PlayAssetDeliveryAssetBundleProvider replaced by dependencies.

When Addressables.LoadAssetAsync(resourceAddress), it will fetch the target resource and its all dependencies. Then the target resources is part of the asset pack and try to download it if not installed. Because the download method in PAD sample is void not async, it make execute the others dependencies where I believe generate new ProvideHandle then overwrite ProvideHandle m_ProviderInterface. So when the PAD download completed, the callback invoke other m_ProviderInterface.

image

from addressables-sample.

restush avatar restush commented on August 28, 2024

@JPerryOddGames After I make async, the dependencies will wait for download to be completed. So there is no invalid handle any more because overwritten the m_ProviderInterface. Here is my modified codes. Notice I move m_ProviderInterface = providerInterface; from Provide method to LoadFromAssetPack method and add while loop before it.

image

from addressables-sample.

JPerryOddGames avatar JPerryOddGames commented on August 28, 2024

Apologies @restush , I never received a notification from your replies in this thread. We did manage to solve the issue on the 1st of Feb and have not seen it since (in 10 weeks) so I assume it's entirely fixed.

I'll include my fix below. Note that m_ProviderInterface no longer exists in class-scope at all; Instead, the object is passed directly to the methods that require it.

Code
using System;
using System.ComponentModel;
using System.IO;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Android;
using UnityEngine.ResourceManagement.ResourceProviders;

namespace AddressablesPlayAssetDelivery
{
    /// <summary>
    /// Ensures that the asset pack containing the AssetBundle is installed/downloaded before attemping to load the bundle.
    /// </summary>
    [DisplayName("Play Asset Delivery Provider")]
    public class PlayAssetDeliveryAssetBundleProvider : AssetBundleProvider
    {
        public override void Provide(ProvideHandle providerInterface)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            LoadFromAssetPack(providerInterface);
#else
            base.Provide(providerInterface);
#endif
        }

#if UNITY_ANDROID
        private void LoadFromAssetPack(ProvideHandle providerInterface)
        {
            string bundleName = Path.GetFileNameWithoutExtension(providerInterface.Location.InternalId);
            if (!PlayAssetDeliveryRuntimeData.Instance.BundleNameToAssetPack.ContainsKey(bundleName))
            {
                // Bundle is either assigned to the generated asset packs, or not assigned to any asset pack
                base.Provide(providerInterface);
            }
            else
            {
                // Bundle is assigned to a custom fast-follow or on-demand asset pack
                string assetPackName = PlayAssetDeliveryRuntimeData.Instance.BundleNameToAssetPack[bundleName].AssetPackName;
                if (PlayAssetDeliveryRuntimeData.Instance.AssetPackNameToDownloadPath.ContainsKey(assetPackName))
                {
                    // Asset pack is already downloaded
                    base.Provide(providerInterface);
                }
                else
                {
                    // Download the asset pack
                    DownloadRemoteAssetPack(assetPackName, providerInterface);
                }
            }
        }

        private async void DownloadRemoteAssetPack(string assetPackName, ProvideHandle providerInterface)
        {
            // Note that most methods in the AndroidAssetPacks class are either direct wrappers of java APIs in Google's PlayCore plugin,
            // or depend on values that the PlayCore API returns. If the PlayCore plugin is missing, calling these methods will throw an InvalidOperationException exception.
            try
            {
                await ProcessRequest(Google.Play.AssetDelivery.PlayAssetDelivery.RetrieveAssetPackAsync(assetPackName), assetPackName, providerInterface);
            }
            catch (InvalidOperationException ioe)
            {
                Debug.LogError($"Cannot retrieve state for asset pack '{assetPackName}'. PlayCore Plugin is not installed: {ioe.Message}");
                providerInterface.Complete(this, false, new Exception("exception"));
            }
        }

        private async Task ProcessRequest(Google.Play.AssetDelivery.PlayAssetPackRequest request, string assetPackName, ProvideHandle providerInterface)
        {
            while (!request.IsDone)
                await System.Threading.Tasks.Task.Yield();

            Debug.Log($"[PlatAssetDeliveryBundleProvider] {assetPackName} finished downloading, now waiting for installation");

            while (request.Error != Google.Play.AssetDelivery.AssetDeliveryErrorCode.NoError && (request.Status != Google.Play.AssetDelivery.AssetDeliveryStatus.Available || request.Status != Google.Play.AssetDelivery.AssetDeliveryStatus.Loaded))
                await System.Threading.Tasks.Task.Yield();

            Debug.Log($"[PlatAssetDeliveryBundleProvider] {assetPackName} finished waiting status: {request.Status}, error: {request.Error}");

            string message = string.Empty;
            if (request.Error != Google.Play.AssetDelivery.AssetDeliveryErrorCode.NoError)
                message = $"Failed to retrieve the state of asset pack '{assetPackName}'.";
            else
            {
                string assetPackPath = AndroidAssetPacks.GetAssetPackPath(assetPackName);

                if (!string.IsNullOrEmpty(assetPackPath))
                {
                    // Asset pack was located on device. Proceed with loading the bundle.
                    PlayAssetDeliveryRuntimeData.Instance.AssetPackNameToDownloadPath[assetPackName] = assetPackPath;
                    base.Provide(providerInterface);
                }
                else
                    message = $"Downloaded asset pack '{assetPackName}' but cannot locate it on device.";
            }

            if (!string.IsNullOrEmpty(message))
            {
                Debug.LogError(message);
                providerInterface.Complete(this, false, new Exception("exception"));
            }
        }
#endif
    }
}

from addressables-sample.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.