Search Unity

Question NativeList InvalidOperationException: Attempted to operate on {size} bytes of memory: nonsensical

Discussion in 'Entity Component System' started by jRocket, Mar 27, 2022.

  1. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    Whenever I call NativeList.Add(), I am getting this exception. Anyone have any idea how this could happen?


    InvalidOperationException: Attempted to operate on {size} bytes of memory: nonsensical
    Unity.Collections.Memory.CheckByteCountIsReasonable (System.Int64 size) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/Memory.cs:153)
    Unity.Collections.Memory+Unmanaged+Array.Resize (System.Void* oldPointer, System.Int64 oldCount, System.Int64 newCount, Unity.Collections.AllocatorManager+AllocatorHandle allocator, System.Int64 size, System.Int32 align) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/Memory.cs:78)
    Unity.Collections.Memory+Unmanaged.Allocate (System.Int64 size, System.Int32 align, Unity.Collections.AllocatorManager+AllocatorHandle allocator) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/Memory.cs:20)
    Unity.Collections.AllocatorManager.TryLegacy (Unity.Collections.AllocatorManager+Block& block) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/AllocatorManager.cs:851)
    Unity.Collections.AllocatorManager.Try (Unity.Collections.AllocatorManager+Block& block) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/AllocatorManager.cs:883)
    Unity.Collections.AllocatorManager+AllocatorHandle.Try (Unity.Collections.AllocatorManager+Block& block) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/AllocatorManager.cs:511)
    Unity.Collections.AllocatorManager.AllocateBlock[T] (T& t, System.Int32 sizeOf, System.Int32 alignOf, System.Int32 items) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/AllocatorManager.cs:34)
    Unity.Collections.AllocatorManager.Allocate[T] (T& t, System.Int32 sizeOf, System.Int32 alignOf, System.Int32 items) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/AllocatorManager.cs:46)
    Unity.Collections.LowLevel.Unsafe.UnsafeList`1[T].Realloc[U] (U& allocator, System.Int32 newCapacity) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/UnsafeList.cs:375)
    Unity.Collections.LowLevel.Unsafe.UnsafeList`1[T].SetCapacity[U] (U& allocator, System.Int32 capacity) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/UnsafeList.cs:410)
    Unity.Collections.LowLevel.Unsafe.UnsafeList`1[T].SetCapacity (System.Int32 capacity) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/UnsafeList.cs:419)
    Unity.Collections.LowLevel.Unsafe.UnsafeList`1[T].Resize (System.Int32 length, Unity.Collections.NativeArrayOptions options) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/UnsafeList.cs:351)
    Unity.Collections.LowLevel.Unsafe.UnsafeList`1[T].Add (T& value) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/UnsafeList.cs:493)
    Unity.Collections.NativeList`1[T].Add (T& value) (at Library/PackageCache/com.unity.collections@1.2.3/Unity.Collections/NativeList.cs:332)
     
  2. DominiqueSandoz

    DominiqueSandoz

    Joined:
    Aug 29, 2017
    Posts:
    25
    Had the same and went nuts. But then I tried not creating those NativeLists inside the Job but before and pass them in via the struct & the error went away.

    Edit:
    Ok, somehow the fix did not work anymore today. Instead, today removing `CompileSynchronously= True` fixed it :/
     
    Last edited: Apr 11, 2022
  3. scottygavin

    scottygavin

    Joined:
    Feb 25, 2021
    Posts:
    10
    Adding too many items can result in this error