Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.07k stars 1.15k forks source link

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

Closed Lchikar closed 3 years ago

Lchikar commented 3 years ago

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

tdmowrer commented 3 years ago

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;
}
Lchikar commented 3 years ago

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

tdmowrer commented 3 years ago

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

todds-unity commented 3 years ago

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