From 33d3b7eea77517cd2fcce59c5e9128aa74511f9f Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 10 Jan 2023 13:08:10 +0100 Subject: Fix Callable call error reporting. * Fix potential crash when using bind in `Variant::get_callable_error_text()` * Properly compute bound arguments so they can be properly shown. * Add a function to obtain the actual bound arguments. --- core/variant/callable.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'core/variant/callable.cpp') diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp index fd85fe78f6..2f2acc55a6 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -117,6 +117,7 @@ Callable Callable::bindv(const Array &p_arguments) { } Callable Callable::unbind(int p_argcount) const { + ERR_FAIL_COND_V_MSG(p_argcount <= 0, Callable(*this), "Amount of unbind() arguments must be 1 or greater."); return Callable(memnew(CallableCustomUnbind(*this, p_argcount))); } @@ -159,6 +160,27 @@ int Callable::get_bound_arguments_count() const { } } +void Callable::get_bound_arguments_ref(Vector &r_arguments, int &r_argcount) const { + if (!is_null() && is_custom()) { + custom->get_bound_arguments(r_arguments, r_argcount); + } else { + r_arguments.clear(); + r_argcount = 0; + } +} + +Array Callable::get_bound_arguments() const { + Vector arr; + int ac; + get_bound_arguments_ref(arr, ac); + Array ret; + ret.resize(arr.size()); + for (int i = 0; i < arr.size(); i++) { + ret[i] = arr[i]; + } + return ret; +} + CallableCustom *Callable::get_custom() const { ERR_FAIL_COND_V_MSG(!is_custom(), nullptr, vformat("Can't get custom on non-CallableCustom \"%s\".", operator String())); @@ -370,6 +392,11 @@ int CallableCustom::get_bound_arguments_count() const { return 0; } +void CallableCustom::get_bound_arguments(Vector &r_arguments, int &r_argcount) const { + r_arguments = Vector(); + r_argcount = 0; +} + CallableCustom::CallableCustom() { ref_count.init(); } -- cgit v1.2.3