Godot: "Cannot get ratio when minimum and maximum value are equal"

Created on 29 Oct 2020  路  8Comments  路  Source: godotengine/godot

Godot version:

3.2.3 stable

OS/device including version:

Windows

Issue description:

When I set a slider min and max val to 0, it throws the following error:

Cannot get ratio when minimum and maximum value are equal

Q: Why do I need this at all?
A: I'm creating an Undo slider like in ZBrush.
When a project starts, there's nothing to undo, so the undo slider max val is 0 (and min val is always 0)

Steps to reproduce:
set a slider (HSlider or VSlider) min and max val to an equal value, say to 0, in Ispector or with a script.

Minimal reproduction project:

discussion gui

Most helpful comment

@Ev1lbl0w these are proper values.
At least many popular UI frameworks work fine with setting equal min max values:
Vue:
https://vuetifyjs.com/en/components/sliders/
Angular:
https://material.angular.io/components/slider/examples
Kivy:
Slider(min=0, max=0, value=0)
etc

I see a work-round for setting max value to something more than min val + setting editable to false, although this is inelegant and requires more code
I think the user shouldn't have any problems with this, so this bug should either be fixed, or this feature should be documented.

All 8 comments

At some point, this behaviour would yield dividing by zero. First of all, if the min and max are zero and the value is also zero, where does the thumb of the slider reside? What should the percentage show if percent_visible is true?

At this point, does not sound like a bug. If anything, throw a configuration error.

Just like @nathanfranke said, this doesn't look like a bug; the slider is not meant to be used with non proper max and min values, so it's kind of creating a problem where there isn't one.

@Ev1lbl0w these are proper values.
At least many popular UI frameworks work fine with setting equal min max values:
Vue:
https://vuetifyjs.com/en/components/sliders/
Angular:
https://material.angular.io/components/slider/examples
Kivy:
Slider(min=0, max=0, value=0)
etc

I see a work-round for setting max value to something more than min val + setting editable to false, although this is inelegant and requires more code
I think the user shouldn't have any problems with this, so this bug should either be fixed, or this feature should be documented.

@me2beats That's a fair argument, but before changes will be made we must agree on exact behaviour, including but not necessarily limited to these questions:

  • Where should the thumb of the slider reside?
  • What should the percentage show?
  • What should get_as_ratio return? 0.0? NaN?

According to the above links, when min = max, the slider gets all the way up to 100%, so the measure value should be equal to max.

Btw, this error does not seem to interfere with starting the game. But not sure that ignoring it won't cause the game to crash someday.

  • now (with min 0 and max 0) the thumb of the slider resides left, like in kivy.
    Vue and Angular reside right.
    Not sure which one is more intuitive.
    ZBrush in its Undo slider shows the thumb left, when there's no undo history
  • percentage is something that the user would implement on his own? Didn't find such an option in godot.
    I would let the user decide it for himself.
  • with min 0 and max 0, ratio returns 0. I think that's ok in this case.

percentage is something that the user would implement on his own? Didn't find such an option in godot.

Understandable, I was actually referring to percent_visible in ProgressBar which extends Range.

This error was added in #33583.

Btw, this error does not seem to interfere with starting the game.

This is because most error macros are not harmful, those are just return statements with error printing. 馃檪

In my opinion, the class implementation should just handle those cases gracefully, and return either 0 or 1. Returning 1 may be less error-prone because it's unlikely to lead to division by zero.

Or even INF, which is also available in GDScript. 馃槃

Was this page helpful?
0 / 5 - 0 ratings