byte[] a = new byte[93];
unsafe
{
fixed (byte* p = &a[0])
{
NativeArray<byte> na = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<byte>(p, a.Length, Allocator.None);
var b = na[0];// Fails with NullReferenceException
}
}
Documentation states that “Allocator.None can be used in case the data is owned externally, while the others can be used to transfer control to the NativeArray”.
Can’t we share memory fixed in the heap with Unity’s C++ functions?
I’d like to use Mesh.SetVertices(NativeArray), to avoid unnecessary memory copy and allocation.
I have my vertices in the heap in a Vector3[ ], I pin it, and hope I can use NativeArrayUnsafeUtility to share the buffer with the C++ side.
Unsuccessfully until now. Mesh.SetVertices(NativeArray) fails with the same NullReferenceException as var b = na[0] in my example…