Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Bug WebGL app crashes when I call InstantiateAsync

Discussion in 'Addressables' started by epratt, Jul 6, 2022.

  1. epratt

    epratt

    Joined:
    Oct 15, 2019
    Posts:
    16
    I have some code where I load a list of IResourceLocation using a label I created for my assets.
    My code loads them one at a time as the user clicks an arrow key to loop through them one-by-one.

    When I run this in Unity it works flawlessly.

    I'll then do a WebGL build and deploy it in a Docker container that I have hosted on my own machine.

    I have console output that indicates that it finds the locations just fine. However, as soon as it calls InstantiateAsync it crashes. In Chrome it gives me the "aw snap" error. Also crashes in Edge with a "This page is having a problem" error. In Firefox it doesn't crash, but it refuses to process anything after that first call to InstantiateAsync. It starts throwing all sorts of null pointer exceptions as though everything loaded previously just went away.

    I've also tried doing a call to LoadAssetAsync before InstantiateAsync, but then it crashes on LoadAssetAsync.

    I'm using Unity 2020.3.28f1 and addressables 1.18.19

    The following is my code:

    Code (CSharp):
    1. IEnumerator Start()
    2.     {
    3.         models = new List<GameObject>();
    4.  
    5.         AsyncOperationHandle<IList<IResourceLocation>> locationHandler = Addressables.LoadResourceLocationsAsync(addressableModelLabel, null);
    6.         yield return locationHandler;
    7.  
    8.         resources = locationHandler.Result; //This returns a list of 7 items
    9.  
    10.         StartCoroutine(LoadAddressable(resources[index])); //index initially set to 0
    11.     }
    12.  
    13.     private IEnumerator LoadAddressable(IResourceLocation reference)
    14.     {
    15.         AsyncOperationHandle<GameObject> instHandle = Addressables.InstantiateAsync(reference, transform);
    16.         yield return instHandle;
    17.  
    18.         GameObject newObject = instHandle.Result;
    19.         string key = resources[refIndex].PrimaryKey;
    20.         newObject.name = key;
    21.         models.Insert(index, newObject);
    22.     }
    I've attached an image of how my addressables are set up.

    The settings for each group has the defaults for Content Packing & Loading and Content Update Restriction. The addressables settings are also on their defaults.

    In Other Settings I have Manage Stripping Level set to Low. I also tried it with Strip Engine Code unchecked.

    There are no errors in the console. Doing a log dump of chrome also yields no results.
     

    Attached Files:

    Last edited: Jul 6, 2022
  2. epratt

    epratt

    Joined:
    Oct 15, 2019
    Posts:
    16
    Update:

    I'll create a bran new scene, add an empty object and add a script to that object. This is literally everything in that script:

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.AddressableAssets;
    6. using UnityEngine.ResourceManagement.AsyncOperations;
    7. using UnityEngine.ResourceManagement.ResourceLocations;
    8.  
    9. public class TestingAddressables : MonoBehaviour
    10. {
    11.     // Start is called before the first frame update
    12.     IEnumerator Start()
    13.     {
    14.         yield return Addressables.InitializeAsync();
    15.  
    16.         AsyncOperationHandle<IList<IResourceLocation>> locationHandler = Addressables.LoadResourceLocationsAsync("my-label", null);
    17.         yield return locationHandler;
    18.  
    19.         var resources = locationHandler.Result;
    20.  
    21.         Console.WriteLine(resources.Count + " resources found");
    22.  
    23.         yield return LoadAddressable(resources[0]);
    24.     }
    25.  
    26.     private IEnumerator LoadAddressable(IResourceLocation reference)
    27.     {
    28.         Console.WriteLine("Attempting to instantiate reference");
    29.         AsyncOperationHandle<GameObject> instHandle = Addressables.InstantiateAsync(reference, transform);
    30.         yield return instHandle;
    31.  
    32.     }
    33. }
    The console outputs "7 resources found" then "Attempting to instantiate reference" and then it crashes.
     
  3. epratt

    epratt

    Joined:
    Oct 15, 2019
    Posts:
    16
    Looks like if there are too many resources in an addressable group it causes the crash.

    Edit: Most of my prefabs include fbx files and can be large. After splitting them up so only 2 prefabs were in each group it solved my problem. webgl deployments no longer crash after this.
     
    Last edited: Jul 11, 2022