Fix crash when unboxing managed structure with refs into Variant
This commit is contained in:
@@ -649,7 +649,6 @@ namespace FlaxEngine.Interop
|
||||
Type type = value.GetType();
|
||||
if (!type.IsValueType)
|
||||
return ManagedHandle.ToIntPtr(handle);
|
||||
|
||||
return ValueTypeUnboxer.GetPointer(value, type);
|
||||
}
|
||||
|
||||
|
||||
@@ -1077,13 +1077,14 @@ namespace FlaxEngine.Interop
|
||||
alloc.ptr = new IntPtr(NativeAlloc(size));
|
||||
alloc.size = size;
|
||||
}
|
||||
|
||||
Unsafe.Write<T>(alloc.ptr.ToPointer(), value);
|
||||
return alloc.ptr;
|
||||
}
|
||||
|
||||
private static IntPtr UnboxPointer<T>(object value, object converter) where T : struct
|
||||
{
|
||||
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>()) // Cannot pin structure with references
|
||||
return IntPtr.Zero;
|
||||
PinValue(value);
|
||||
return new IntPtr(Unsafe.AsPointer(ref Unsafe.Unbox<T>(value)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user