Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.03k stars 1.13k forks source link

ARFace's GetUndisposable throws error on UnityEditor #343

Closed asus4 closed 4 years ago

asus4 commented 4 years ago

Hi, I am making an ARFoundation remote simulation tool. Making a subclass of XRFaceSubsystem that works on UnityEditor.

ARFace.GetUndisposable throws on only UnityEditor, since NativeArray.cs is checked read/write access on Editor. it works if remove GetUndisposable and simply return the native array. any workaround?

NativeArray.cs source code

// ARFace.cs
 public unsafe NativeArray<Vector3> vertices
 {
    get
    {
         // throws error on Editor
         return GetUndisposable(m_FaceMesh.vertices);
         // It works
         return m_FaceMesh.vertices;
     }
}

Error Message

NullReferenceException: Object reference not set to an instance of an object
Unity.Collections.NativeArray`1[T].CheckElementReadAccess (System.Int32 index) (at /Users/builduser/buildslave/unity/build/Runtime/Export/NativeArray/NativeArray.cs:117)
Unity.Collections.NativeArray`1[T].get_Item (System.Int32 index) (at /Users/builduser/buildslave/unity/build/Runtime/Export/NativeArray/NativeArray.cs:139)
Unity.Collections.NativeArray`1+Enumerator[T].get_Current () <0x14a2783c0 + 0x0007a> in <85963591c1a04aad836445db604e7807>:0
UnityEngine.XR.ARFoundation.ARFaceMeshVisualizer.TryCopyToList[T] (Unity.Collections.NativeArray`1[T] array, System.Collections.Generic.List`1[T] list) (at Library/PackageCache/com.unity.xr.arfoundation@3.0.0-preview.4/Runtime/AR/ARFaceMeshVisualizer.cs:46)
UnityEngine.XR.ARFoundation.ARFaceMeshVisualizer.SetMeshTopology () (at Library/PackageCache/com.unity.xr.arfoundation@3.0.0-preview.4/Runtime/AR/ARFaceMeshVisualizer.cs:61)
UnityEngine.XR.ARFoundation.ARFaceMeshVisualizer.SetVisible (System.Boolean visible) (at Library/PackageCache/com.unity.xr.arfoundation@3.0.0-preview.4/Runtime/AR/ARFaceMeshVisualizer.cs:34)
UnityEngine.XR.ARFoundation.ARFaceMeshVisualizer.UpdateVisibility () (at Library/PackageCache/com.unity.xr.arfoundation@3.0.0-preview.4/Runtime/AR/ARFaceMeshVisualizer.cs:103)
UnityEngine.XR.ARFoundation.ARFaceMeshVisualizer.OnUpdated (UnityEngine.XR.ARFoundation.ARFaceUpdatedEventArgs eventArgs) (at Library/PackageCache/com.unity.xr.arfoundation@3.0.0-preview.4/Runtime/AR/ARFaceMeshVisualizer.cs:108)
UnityEngine.XR.ARFoundation.ARFace.Update () (at Library/PackageCache/com.unity.xr.arfoundation@3.0.0-preview.4/Runtime/AR/ARFace.cs:123)

Environment

tdmowrer commented 4 years ago

Thanks for reporting. This does not happen in current master, and, looking at the code for ARFace.cs, it looks like everything is guarded correctly. It may have been an issue in a 3.0 preview, but it looks like it was fixed. Please reopen if you are still seeing this.

Lchikar commented 3 years ago

Hello,

I have dealt with the exact same issue lately while working on an ARFoundation simulation tool as well. I managed to solve it temporarily with what @asus4 shared in his thread.

Are there any updates about this issue today ?

Environment : Unity Editor 2019.4.24f1 ARFoundation 4.1.7 ARKit 4.1.7 ARCore 4.1.7