diff --git a/Source/Engine/Engine/NativeInterop.cs b/Source/Engine/Engine/NativeInterop.cs index a20af8490..43d6ea91c 100644 --- a/Source/Engine/Engine/NativeInterop.cs +++ b/Source/Engine/Engine/NativeInterop.cs @@ -2045,8 +2045,10 @@ namespace FlaxEngine return (bool)returnObject ? boolTruePtr : boolFalsePtr; else if (methodHolder.method.ReturnType == typeof(Type)) return GCHandle.ToIntPtr(GetTypeGCHandle(Unsafe.As(returnObject))); - else if (methodHolder.method.ReturnType == typeof(object[])) - return GCHandle.ToIntPtr(GCHandle.Alloc(ManagedArray.WrapNewArray(ManagedArrayToGCHandleArray(Unsafe.As(returnObject))), GCHandleType.Weak)); + else if (methodHolder.method.ReturnType.IsArray && ArrayFactory.GetMarshalledType(methodHolder.method.ReturnType.GetElementType()) == methodHolder.method.ReturnType.GetElementType()) + return GCHandle.ToIntPtr(GCHandle.Alloc(ManagedArray.WrapNewArray(Unsafe.As(returnObject)), GCHandleType.Weak)); + else if (methodHolder.method.ReturnType.IsArray) + return GCHandle.ToIntPtr(GCHandle.Alloc(ManagedArray.WrapNewArray(ManagedArrayToGCHandleArray(Unsafe.As(returnObject))), GCHandleType.Weak)); else return GCHandle.ToIntPtr(GCHandle.Alloc(returnObject, GCHandleType.Weak)); } diff --git a/Source/Engine/Engine/NativeInterop_Invoker.cs b/Source/Engine/Engine/NativeInterop_Invoker.cs index ccbe468d9..5e02cbf14 100644 --- a/Source/Engine/Engine/NativeInterop_Invoker.cs +++ b/Source/Engine/Engine/NativeInterop_Invoker.cs @@ -59,8 +59,10 @@ namespace FlaxEngine return (bool)(object)returnValue ? boolTruePtr : boolFalsePtr; else if (typeof(TRet) == typeof(Type)) return returnValue != null ? GCHandle.ToIntPtr(GetTypeGCHandle(Unsafe.As(returnValue))) : IntPtr.Zero; - else if (typeof(TRet) == typeof(object[])) - return returnValue != null ? GCHandle.ToIntPtr(GCHandle.Alloc(ManagedArray.WrapNewArray(ManagedArrayToGCHandleArray(Unsafe.As(returnValue))), GCHandleType.Weak)) : IntPtr.Zero; + else if (typeof(TRet).IsArray && ArrayFactory.GetMarshalledType(typeof(TRet).GetElementType()) == typeof(TRet).GetElementType()) + return returnValue != null ? GCHandle.ToIntPtr(GCHandle.Alloc(ManagedArray.WrapNewArray(Unsafe.As(returnValue)), GCHandleType.Weak)) : IntPtr.Zero; + else if (typeof(TRet).IsArray) + return returnValue != null ? GCHandle.ToIntPtr(GCHandle.Alloc(ManagedArray.WrapNewArray(ManagedArrayToGCHandleArray(Unsafe.As(returnValue))), GCHandleType.Weak)) : IntPtr.Zero; else return returnValue != null ? GCHandle.ToIntPtr(GCHandle.Alloc(returnValue, GCHandleType.Weak)) : IntPtr.Zero; }