From 76bd7d796bb898bca5878fcd9e1aec3922c20ead Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Fri, 15 Jan 2021 23:13:08 +0100 Subject: [PATCH] Make Range return 1.0 ratio if minimum and maximum values are equal An error message is also no longer printed. This matches the behavior found in most UI frameworks where having equal minimum and maximum values is considered acceptable. This closes #43179. (cherry picked from commit 44204ec32d30a59b77c75a38406676774885a595) --- scene/gui/range.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index ba6d2812697..1142f5fe9ea 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -170,8 +170,10 @@ void Range::set_as_ratio(double p_value) { set_value(v); } double Range::get_as_ratio() const { - - ERR_FAIL_COND_V_MSG(Math::is_equal_approx(get_max(), get_min()), 0.0, "Cannot get ratio when minimum and maximum value are equal."); + if (Math::is_equal_approx(get_max(), get_min())) { + // Avoid division by zero. + return 1.0; + } if (shared->exp_ratio && get_min() >= 0) {