Fix crash when unboxing managed structure with refs into Variant

This commit is contained in:
Wojtek Figat
2023-08-29 11:42:47 +02:00
parent 597f186902
commit c7d277ca74
2 changed files with 2 additions and 2 deletions

View File

@@ -649,7 +649,6 @@ namespace FlaxEngine.Interop
Type type = value.GetType();
if (!type.IsValueType)
return ManagedHandle.ToIntPtr(handle);
return ValueTypeUnboxer.GetPointer(value, type);
}

View File

@@ -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)));
}