From 44d4f637a1866ee9c7fa725c27094e5a6cdd0bf1 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Wed, 5 Jun 2024 16:53:21 +0200 Subject: [PATCH] C#: Skip method name when checking CallError When invoking `call`, the arguments contain the method name. This argument must be skipped; otherwise, the `error.argument` index will be off. --- .../GodotSharp/Core/NativeInterop/ExceptionUtils.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs index 04b6c2e743f5..6b5d7fed784a 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs @@ -143,7 +143,7 @@ namespace Godot.NativeInterop if (error.Error != godot_variant_call_error_error.GODOT_CALL_ERROR_CALL_OK) { using godot_variant instanceVariant = VariantUtils.CreateFromGodotObjectPtr(instance); - string where = GetCallErrorWhere(method, &instanceVariant, args, argCount); + string where = GetCallErrorWhere(ref error, method, &instanceVariant, args, argCount); string errorText = GetCallErrorMessage(error, where, args); GD.PushError(errorText); } @@ -161,7 +161,7 @@ namespace Godot.NativeInterop } } - private unsafe static string GetCallErrorWhere(godot_string_name method, godot_variant* instance, godot_variant** args, int argCount) + private unsafe static string GetCallErrorWhere(ref godot_variant_call_error error, godot_string_name method, godot_variant* instance, godot_variant** args, int argCount) { string? methodstr = null; string basestr = GetVariantTypeName(instance); @@ -171,6 +171,10 @@ namespace Godot.NativeInterop if (argCount >= 1) { methodstr = VariantUtils.ConvertToString(*args[0]); + if (error.Error == godot_variant_call_error_error.GODOT_CALL_ERROR_CALL_ERROR_INVALID_ARGUMENT) + { + error.Argument += 1; + } } }