diff --git a/Source/Engine/Engine/NativeInterop.Unmanaged.cs b/Source/Engine/Engine/NativeInterop.Unmanaged.cs index 8837d460b..879f804d2 100644 --- a/Source/Engine/Engine/NativeInterop.Unmanaged.cs +++ b/Source/Engine/Engine/NativeInterop.Unmanaged.cs @@ -649,7 +649,6 @@ namespace FlaxEngine.Interop Type type = value.GetType(); if (!type.IsValueType) return ManagedHandle.ToIntPtr(handle); - return ValueTypeUnboxer.GetPointer(value, type); } diff --git a/Source/Engine/Engine/NativeInterop.cs b/Source/Engine/Engine/NativeInterop.cs index e75877878..dd6087b98 100644 --- a/Source/Engine/Engine/NativeInterop.cs +++ b/Source/Engine/Engine/NativeInterop.cs @@ -1077,13 +1077,14 @@ namespace FlaxEngine.Interop alloc.ptr = new IntPtr(NativeAlloc(size)); alloc.size = size; } - Unsafe.Write(alloc.ptr.ToPointer(), value); return alloc.ptr; } private static IntPtr UnboxPointer(object value, object converter) where T : struct { + if (RuntimeHelpers.IsReferenceOrContainsReferences()) // Cannot pin structure with references + return IntPtr.Zero; PinValue(value); return new IntPtr(Unsafe.AsPointer(ref Unsafe.Unbox(value))); }