Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[.NET] Fix serialization of delegates capturing variables #83217

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
paulloz marked this conversation as resolved.
Show resolved Hide resolved
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);
raulsntos marked this conversation as resolved.
Show resolved Hide resolved
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
Loading