From 8d5c30ce83c2ec69403338f9bc2809aef6f1539b Mon Sep 17 00:00:00 2001 From: Gary Oberbrunner Date: Mon, 30 Apr 2018 15:04:30 -0400 Subject: [PATCH] Handle missing arg pointer in get_call_error_text I had a situation coming from godot-python where the caller of Variant::get_call_error_text() passed null for `p_argptrs`. In addition to fixing that in the caller, seems like good practice to defend against that situation in the callee to prevent a crash. So this patch just substitutes some semi-useful text for the source type name and keeps going so the user's actual error gets emitted. --- core/variant.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/variant.cpp b/core/variant.cpp index 5d48c8785e9..a6df95e3105 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -3167,7 +3167,11 @@ String Variant::get_call_error_text(Object *p_base, const StringName &p_method, if (ce.error == Variant::CallError::CALL_ERROR_INVALID_ARGUMENT) { int errorarg = ce.argument; - err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(ce.expected) + "."; + if (p_argptrs) { + err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(ce.expected) + "."; + } else { + err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(ce.expected) + "."; + } } else if (ce.error == Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) { err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; } else if (ce.error == Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) {