Skip to content

Commit

Permalink
Merge pull request #83217 from paulloz/fix/81903-delegate-capture-ser…
Browse files Browse the repository at this point in the history
…ialization

[.NET] Fix serialization of delegates capturing variables
  • Loading branch information
akien-mga committed Apr 5, 2024
2 parents 79de2ea + c310ecc commit 72f9f8d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private static bool TrySerializeSingleDelegate(Delegate @delegate, [MaybeNullWhe

foreach (FieldInfo field in fields)
{
Type fieldType = field.GetType();
Type fieldType = field.FieldType;

Variant.Type variantType = GD.TypeToVariantType(fieldType);

Expand All @@ -216,7 +216,7 @@ private static bool TrySerializeSingleDelegate(Delegate @delegate, [MaybeNullWhe

static byte[] VarToBytes(in godot_variant var)
{
NativeFuncs.godotsharp_var_to_bytes(var, false.ToGodotBool(), out var varBytes);
NativeFuncs.godotsharp_var_to_bytes(var, godot_bool.True, out var varBytes);
using (varBytes)
return Marshaling.ConvertNativePackedByteArrayToSystemArray(varBytes);
}
Expand Down Expand Up @@ -483,7 +483,7 @@ private static bool TryDeserializeSingleDelegate(byte[] buffer, [MaybeNullWhen(f

if (fieldInfo != null)
{
var variantValue = GD.BytesToVar(valueBuffer);
var variantValue = GD.BytesToVarWithObjects(valueBuffer);
object? managedValue = RuntimeTypeConversionHelper.ConvertToObjectOfType(
(godot_variant)variantValue.NativeVar, fieldInfo.FieldType);
fieldInfo.SetValue(recreatedTarget, managedValue);
Expand Down Expand Up @@ -799,7 +799,7 @@ private static readonly System.Collections.Generic.Dictionary<Type, ConvertToSys
return func(variant);

if (typeof(GodotObject).IsAssignableFrom(type))
return Convert.ChangeType(VariantUtils.ConvertTo<GodotObject>(variant), type, CultureInfo.InvariantCulture);
return VariantUtils.ConvertTo<GodotObject>(variant);

if (typeof(GodotObject[]).IsAssignableFrom(type))
{
Expand All @@ -818,7 +818,7 @@ static GodotObject[] ConvertToSystemArrayOfGodotObject(in godot_array nativeArra
}

using var godotArray = NativeFuncs.godotsharp_variant_as_array(variant);
return Convert.ChangeType(ConvertToSystemArrayOfGodotObject(godotArray, type), type, CultureInfo.InvariantCulture);
return ConvertToSystemArrayOfGodotObject(godotArray, type);
}

if (type.IsEnum)
Expand Down

0 comments on commit 72f9f8d

Please sign in to comment.