Hi,
Any idea of what can be causing this error:
NullReferenceException: Object reference not set to an instance of an object
System.Buffer.memcpy4 (System.Byte* dest, System.Byte* src, System.Int32 size) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Buffer.Memcpy (System.Byte* dest, System.Byte* src, System.Int32 size) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.String.memcpy (System.Byte* dest, System.Byte* src, System.Int32 size) (at <437ba245d8404784b9fbab9b439ac908>:0)
Unity.Collections.LowLevel.Unsafe.UnsafeUtility.ReadArrayElement[T] (System.Void* source, System.Int32 index) (at <7d22f8e71133418c87c7b26ea181f3e3>:0)
Unity.Collections.NativeSortExtension.Partition[T,U] (System.Void* array, System.Int32 lo, System.Int32 hi, U comp) (at Library/PackageCache/com.unity.collections@0.1.1-preview/Unity.Collections/NativeSort.cs:142)
It’s weird because the code runs up to the first of these lines but crashes on the secons:
…
while (comp.Compare(pivot, UnsafeUtility.ReadArrayElement(array, ++left)) > 0) ;
while (comp.Compare(pivot, UnsafeUtility.ReadArrayElement(array, --right)) < 0) ;
…
The function where it crashes is
unsafe static int Partition<T, U>(void* array, int lo, int hi, U comp) where T : struct where U : IComparer
of class NativeSortExtension.
I’m sorting a NativeList:
var array = new NativeList<SpatialRender>(Allocator.TempJob);
And sorting by calling sort function on the array:
array.Sort(comparer);
Where SpatialRender is a struct:
public struct SpatialRender
{
public float3 location;
public int renderDataIndex;
public Matrix4x4 matrix;
public Vector4 frame;
}
and comparer is a struct of type:
protected struct LocationComparer : IComparer<SpatialRender>
{
public int Compare(SpatialRender a, SpatialRender b)
{
if (a.location.y < b.location.y)
return 1;
else
return -1;
}
}
On Unity 2019.3.0f5
Entities preview.17 - 0.5.0
Collections preview.9 - 0.5.0
Burst 1.2.1
Thanks.