summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2021-01-15 23:13:08 +0100
committerHugo Locurcio <hugo.locurcio@hugo.pro>2021-01-15 23:14:50 +0100
commit44204ec32d30a59b77c75a38406676774885a595 (patch)
tree5eb2266e1484d49784d10633ec226a594234983b /scene
parent05f5c8725ba7d2b2132d3b0a54dc18a46de83411 (diff)
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.
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/range.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp
index b9ac6d7505..1e33ab0758 100644
--- a/scene/gui/range.cpp
+++ b/scene/gui/range.cpp
@@ -171,7 +171,10 @@ void Range::set_as_ratio(double p_value) {
}
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) {
double exp_min = get_min() == 0 ? 0.0 : Math::log(get_min()) / Math::log((double)2);