arfoundation-samples icon indicating copy to clipboard operation
arfoundation-samples copied to clipboard

NativeArrays returned from ARFace's GetUndisposable throw NullReferenceException when accessing an element in the Editor

Open Lchikar opened this issue 5 years ago • 4 comments

Hello @tdmowrer,

I have dealt with the exact same issue as @asus4 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

Lchikar avatar Jun 28 '21 10:06 Lchikar

A fix is coming soon. The correct fix is to add an atomic safety handle when safety checks are enabled (by default, they are enabled in the Editor, but not the Player, which is why you only see this in the Editor). ARFace's GetUndisposable method should look like this:

static unsafe NativeArray<T> GetUndisposable<T>(NativeArray<T> disposable) where T : struct
{
    if (!disposable.IsCreated)
        return default;

    var undisposable = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<T>(
        disposable.GetUnsafePtr(),
        disposable.Length,
        Allocator.None);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
    NativeArrayUnsafeUtility.SetAtomicSafetyHandle(
        ref undisposable,
        NativeArrayUnsafeUtility.GetAtomicSafetyHandle(disposable));
#endif

    return undisposable;
}

tdmowrer avatar Jun 28 '21 18:06 tdmowrer

Thank you for your response, I will try that. Do you know how long until this next fix, maybe ?

Lchikar avatar Jun 30 '21 15:06 Lchikar

I can't be more specific than "soon", unfortunately, but it is our intention to release it as soon as possible.

tdmowrer avatar Jun 30 '21 20:06 tdmowrer

This should now be released in 4.2.0-pre.12.

todds-unity avatar Jul 27 '21 21:07 todds-unity