Search Unity

Unity 2019.1.4f1 - Crash when using MeshFilter.mesh after loading object from a bundle.

Discussion in 'Editor & General Support' started by JBMS, May 30, 2019.

  1. JBMS

    JBMS

    Joined:
    Sep 30, 2017
    Posts:
    6
    My team and I are experiencing consistent crash in the editor when we try to do the following:
    1. Load an object with a mesh filter (and associated mesh) from a bundle.
    2. Create an instance of the loaded object.
    3. Use GetComponent<MeshFilter>() to get the mesh filter on the object instance.
    4. Attempt to use MeshFilter.mesh to access the mesh.
    5. Observe crash.

    The crash dump is attached. I've also attached the Unity project (MeshFilterMeshCrash.zip) we're using to produce this crash. We are reproducing the issue in Unity Unity 2019.1.4f1. Here's how you can reproduce the crash using the test project:
    1. Open the project.
    2. Open the Test scene.
    3. Click the Play button.
    4. Click the Load Object button to load a bundle (object-with-mesh), load an object from the bundle (ObjectWithMesh), and instantiate the object.
    5. Wait for the bundle load, object load, and instantiation to finish. Observe that ObjectWithMesh(Clone) is in the hierarchy.
    6. Click the Access Meshes button.
    7. Observe crash.

    Is anyone else experiencing this? Is this a known issue? Is there any word on a fix?

    Here's the relevant code from the test project. The crash occurs on line 61:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.IO;
    4. using UnityEngine;
    5.  
    6. public class TestHarness : MonoBehaviour
    7. {
    8.     [System.Serializable]
    9.     public struct LoadPayload
    10.     {
    11.         public string m_BundlePath;
    12.         public string m_AssetPath;
    13.     }
    14.  
    15.     public LoadPayload m_LoadPayload;
    16.     public GameObject m_Instance;
    17.  
    18.     public void HandleLoadObjectButtonClick()
    19.     {
    20.         StartCoroutine(LoadObject(m_LoadPayload));
    21.     }
    22.  
    23.     public void HandleAccessMeshesButtonClick()
    24.     {
    25.         AccessMeshes();
    26.     }
    27.  
    28.     private IEnumerator LoadObject(LoadPayload payload)
    29.     {
    30.         string absoluteBundlePath = Path.Combine(Directory.GetCurrentDirectory(), payload.m_BundlePath);
    31.         Debug.Log(absoluteBundlePath);
    32.  
    33.         AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(absoluteBundlePath);
    34.         while (!assetBundleCreateRequest.isDone)
    35.         {
    36.             yield return null;
    37.         }
    38.  
    39.         AssetBundle bundle = assetBundleCreateRequest.assetBundle;
    40.         AssetBundleRequest assetBundleRequest = bundle.LoadAssetAsync(payload.m_AssetPath);
    41.         while (!assetBundleRequest.isDone)
    42.         {
    43.             yield return null;
    44.         }
    45.  
    46.         Object loaded = assetBundleRequest.asset;
    47.         Object obj = Instantiate(loaded);
    48.         m_Instance = obj as GameObject;
    49.     }
    50.  
    51.     private void AccessMeshes()
    52.     {
    53.         List<MeshFilter> meshFilters = new List<MeshFilter>();
    54.         meshFilters.Add(m_Instance.GetComponent<MeshFilter>());
    55.         meshFilters.AddRange(m_Instance.GetComponentsInChildren<MeshFilter>());
    56.  
    57.         for (int i = 0; i < meshFilters.Count; ++i)
    58.         {
    59.             if (meshFilters[i] != null)
    60.             {
    61.                 Mesh mesh = meshFilters[i].mesh;
    62.                 Debug.Log("Mesh is readable: " + mesh.isReadable);
    63.             }
    64.         }
    65.     }
    66. }
     

    Attached Files:

  2. mowax74

    mowax74

    Joined:
    Mar 3, 2015
    Posts:
    97
    Do you know if they fixed this meanwhile in a newer Unity version? We got the same problem like i posted here.