-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
SliderInt/Float Doesn't Handle Max == Min Correctly. #919
Comments
It is illegal to pass a null range to SliderInt / SliderFloat. What would you expect it to happens appart from erroring/asserting? Early 1.0-era version of imgui supported it by disabling the actual slider behavior but that code-path got removed while cleaning up. |
@sprinkle131313 Could you provide a repro for |
@ocornut Ah I linked to the master and it changed before you looked at the link. Here it does max - min, which can lead to division by zero. To reproduce it, just create a SliderInt where min and max are 0 or equal, then in the UI click the slider and drag left/right quickly trying to change the value. |
…o be consistent with other widget behaviors (#919)
You are right that it makes sense namely for integer. That code you linked doesn't affect the value itself, which is why I am reacting to your "the outputted value" comment. I guess because my test bed doesn't throw an exception on divide-by-zero I don't see that affect and the grab is invisible (which may be desirable). I made the display works (and it makes more senses for integers). |
Confusion lies in the fact that I don't think " then the outputted value will be outside the bounds of "min" and "max" when the user attempts to move the slider " was ever true. |
Yah your right, my mistake. A division of zero was happening but I didn't look closely enough to find the right place. If max == min, then this value will be zero Which leads to a division by zero here. Causing It doesn't seem to happen all the time, it might be under a certain condition. Clicking rapidly and moving slowly seems to cause as well as click-holding and moving the mouse rapidly left/right. |
I don't understand your statement, if you look at the code it doesn't appear to read like what you say. (There is one bug, which I'm fixing now, happening for integers if v_min is > v_max if (v_min - v_max)==-1, but that feature was introduced yesterday.) |
I don't think there is any issue left but as you imply so let me know if there's anything I can check. |
Oh but you are still using the old code. I made commits to fix the issues. |
Just tried the master branch code, the bug still seems to exist. Ok that might explain why it seems to happen randomly. It's when Line 6519 in ca9a918
|
Neither
Could you share your style information and what your windows look like? |
…ng bigger than slider width can lead to a division by zero (#919)
Sorry my confusion was thinking that division by zero caused a NaN to occur, but division by zero just causes the value to become infinite, which clamping solves for that issue. The Problem occurs with a NaN which happens with a division of zero by zero (0.0f / 0,0f). I am using all default values from the example, so GrabMinSize is the default. slider_usable_sz is zero because only a lower limit is defined for the slider. Which is |
Ah that makes sense, thanks. It looks like it solved itself (and some other edges cases) with the previous few commits. Now although Looks like this is a solved case? Sorry it took that long! |
Yah it's fixed now, it's no problem as long as it gets fixed eventually. Thanks for taking the time to fix it. |
I just ran into this issue, while moving the slider (mouse down) the value becomes 0, while min=2 and max=2.
Clicking on the slider makes the value 0, while the lower and upper is 2. The code responsible happens here:
and then
Can't we clamp the v_new to be in range v_min, v_max there, or return v_min or v_max, so the values stays in range while dragging?
|
The SliderInt implementation is just a SliderFloat, so the problem exists there as well. If you set min and max to the same value, then the outputted value will be outside the bounds of "min" and "max" when the user attempts to move the slider. It appears it might be because of a division by zero (exists in a few other places as well). Which causes the result to be NaN, which is then converted to an integer in SliderInt.
The text was updated successfully, but these errors were encountered: