From 833a03fbf6605e6e86e69870b654656ced6df824 Mon Sep 17 00:00:00 2001 From: Zae Date: Thu, 21 Mar 2024 23:55:44 +0800 Subject: [PATCH] C#: Fix errors when creating Variant from null array --- .../Core/NativeInterop/VariantUtils.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs index 464b5174281a..94609984ac02 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs @@ -235,13 +235,28 @@ namespace Godot.NativeInterop } public static godot_variant CreateFromSystemArrayOfStringName(Span from) - => CreateFromArray(new Collections.Array(from)); + { + if (from == null) + return default; + using var fromGodot = new Collections.Array(from); + return CreateFromArray((godot_array)fromGodot.NativeValue); + } public static godot_variant CreateFromSystemArrayOfNodePath(Span from) - => CreateFromArray(new Collections.Array(from)); + { + if (from == null) + return default; + using var fromGodot = new Collections.Array(from); + return CreateFromArray((godot_array)fromGodot.NativeValue); + } public static godot_variant CreateFromSystemArrayOfRid(Span from) - => CreateFromArray(new Collections.Array(from)); + { + if (from == null) + return default; + using var fromGodot = new Collections.Array(from); + return CreateFromArray((godot_array)fromGodot.NativeValue); + } public static godot_variant CreateFromSystemArrayOfGodotObject(GodotObject[]? from) {