瀏覽代碼

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.
Hugo Locurcio 4 年之前
父節點
當前提交
44204ec32d
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      scene/gui/range.cpp

+ 4 - 1
scene/gui/range.cpp

@@ -171,7 +171,10 @@ void Range::set_as_ratio(double p_value) {
 }
 }
 
 
 double Range::get_as_ratio() const {
 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) {
 	if (shared->exp_ratio && get_min() >= 0) {
 		double exp_min = get_min() == 0 ? 0.0 : Math::log(get_min()) / Math::log((double)2);
 		double exp_min = get_min() == 0 ? 0.0 : Math::log(get_min()) / Math::log((double)2);