Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot get ratio when minimum and maximum value are equal" #43179

Closed
me2beats opened this issue Oct 29, 2020 · 10 comments · Fixed by #45220
Closed

"Cannot get ratio when minimum and maximum value are equal" #43179

me2beats opened this issue Oct 29, 2020 · 10 comments · Fixed by #45220

Comments

@me2beats
Copy link

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:

@nathanfranke
Copy link
Contributor

nathanfranke commented Oct 29, 2020

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.

@rsubtil
Copy link
Contributor

rsubtil commented Oct 29, 2020

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.

@me2beats
Copy link
Author

me2beats commented Oct 29, 2020

@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.

@nathanfranke
Copy link
Contributor

nathanfranke commented Oct 29, 2020

@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?

@rsubtil
Copy link
Contributor

rsubtil commented Oct 29, 2020

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.

@me2beats
Copy link
Author

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.

@nathanfranke
Copy link
Contributor

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.

@Xrayez
Copy link
Contributor

Xrayez commented Oct 29, 2020

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. 😄

@reyjakai
Copy link

If this is going to take a while to get addressed, can we at least get the error log in the console to link to the line of code that is generating the error?
I've got this thing popping up and failing silently all over my code, and I have no idea where it's coming from.

Calinou added a commit to Calinou/godot that referenced this issue Jan 15, 2021
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 godotengine#43179.
@Calinou
Copy link
Member

Calinou commented Jan 15, 2021

I've got this thing popping up and failing silently all over my code, and I have no idea where it's coming from.

You can use a divide and conquer approach for now. Try removing nodes inheriting from Range from your scene tree until the error no longer pops up.

Also, if you can recompile the editor, you could change this line in scene/gui/range.cpp from:

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.");

To:

ERR_FAIL_COND_V_MSG(Math::is_equal_approx(get_max(), get_min()), 0.0, vformat("Cannot get ratio of %s when minimum (%f) and maximum (%f) value are equal.", get_name(), get_min(), get_max()));

@akien-mga akien-mga added this to the 4.0 milestone Jan 26, 2021
akien-mga pushed a commit to akien-mga/godot that referenced this issue Jan 26, 2021
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 godotengine#43179.

(cherry picked from commit 44204ec)
dDomovoj pushed a commit to dDomovoj/godot that referenced this issue Feb 2, 2021
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 godotengine#43179.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants