Fix using ManagedDictionary when item value type is array

#1305
This commit is contained in:
Wojtek Figat
2023-09-11 15:05:46 +02:00
parent 9afa98e905
commit 1134cfa6a6

View File

@@ -205,6 +205,13 @@ namespace FlaxEngine
internal static void AddDictionaryItem(IDictionary dictionary, object key, object value)
{
// TODO: more generic approach to properly add value that is of custom boxed type? (eg. via NativeInterop.MarshalToManaged)
if (value is ManagedArray managedArray)
{
var managedArrayHandle = ManagedHandle.Alloc(managedArray, GCHandleType.Normal);
value = NativeInterop.MarshalToManaged((IntPtr)managedArrayHandle, managedArray.ArrayType);
managedArrayHandle.Free();
}
dictionary.Add(key, value);
}