#[BUG?] Allocating Persistent NativeArray throws, while NativeList isn't

1 messages · Page 1 of 1 (latest)

amber steeple
#

Here's responsible code that throws on NativeArray, but seems like no such check is done for NativeList, which raises a concern: is NativeArray restriction is redundant or NativeList not checking is a bug?

    [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
    private static void CheckAllocateArguments(int length, Allocator allocator)
    {
      if (allocator <= Allocator.None)
        throw new ArgumentException("Allocator must be Temp, TempJob or Persistent", nameof (allocator));
      if (allocator >= Allocator.FirstUserIndex)
        throw new ArgumentException("Use CollectionHelper.CreateNativeArray for custom allocator", nameof (allocator));
      if (length < 0)
        throw new ArgumentOutOfRangeException(nameof (length), "Length must be >= 0");
    }

@tropic harbor

tropic harbor
#

i think this is just not actually a problem in nativelist for some reason

#

like the nativelist ctor can actually deal with custom allocators

#

because custom allocators are in a package and nativearray is in the engine

opal valley
#

this is my understanding as well FWIW. We expose CollectionHelper.CreateNativeArray() in the Colletions package to add the necessary checks pertaining to custom allocators.

amber steeple
#

wait a second, I showed wrong code

#

@tropic harbor @opal valley
Sorry for confusion, here's actual stack I was too lazy to get

InvalidOperationException: Jobs can only create Temp memory
Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CreateHandle (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle& safety, Unity.Collections.Allocator allocator) (at <ab74fe8c3de74feeafac966c034df8aa>:0)
Unity.Collections.NativeArray`1[T].Allocate (System.Int32 length, Unity.Collections.Allocator allocator, Unity.Collections.NativeArray`1[T]& array) (at <ab74fe8c3de74feeafac966c034df8aa>:0)
Unity.Collections.NativeArray`1[T]..ctor (System.Int32 length, Unity.Collections.Allocator allocator, Unity.Collections.NativeArrayOptions options) (at <ab74fe8c3de74feeafac966c034df8aa>:0)
#

This is thrown when you allocate persistent native array in job

#

meanwhile NativeList is totally fine

tropic harbor
#

fascinating. somebody's wrong for sure, but i'm not sure who yet