-
Notifications
You must be signed in to change notification settings - Fork 891
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
Fix conversion from u32 to c_int #2919
Fix conversion from u32 to c_int #2919
Conversation
@Selene-Amanita thanks for your patch, however I think that your issue is fixed in that PR #2825 could you ensure that? If not it's better to open against that work, since both of them touch the same things. |
Hm, it might be not. cc @notgull |
I don't understand much of the code of this other PR but it does delete the code that this PR modifies so... I see a |
Yeah, I'd at least wait for @notgull to reply. Though, I wonder why you passed that big of the size to window, most windows are limited to u16/i16 under the hood. I think there're other cases in other backends where we don't clamp to max the values. |
Because in Bevy the lack of a max constraint is represented by a So either I guess I can use |
Well we have another bug that I didn't investigate where calling |
But logical sizes are scale agnostic though? It's weird though that you have such an API using infinity instead of, let's say Even winit accepts an |
I wasn't the one that defined this on Bevy's side, but even if it was an
Not if you want to set a constraint only for height or width but not both, you have to provide a value for both or none with Previous to my PR, Bevy checks if both are finite, if one of them are infinite it just ignores the constraint, I want to make it work with one constraint only, but for that I need to provide a maximum value for the one that is not set.
Well yes but in that case where we want to define the "max value that wouldn't be converted to a negative value in Winit's backend because of c_int conversion", this value is a physical size actually, so we need a conversion. |
Clamping is generally good to do, but I'm not sure how we should ensure that consistently across all the backends, maybe each backend internally. For now what you're doing is fine, but it just moves the problem. Anyway, that's up to future changes of winit, and now I'd wait for @notgull since I was about to merge his patch pretty soon and don't want to force rebase on them. |
winit/src/platform_impl/linux/x11/window.rs Line 1273 in 5634305
Apparently it's not fixed, since I still do bitcasting here. |
In this case it's casting a |
I don't see any issue with doing clamping, however I think that the way it should be done is that backend specify internally what |
I'm fine with the current patch if it matters. |
I reimplemented this PR in a653b04 |
Thank you for the work on this! |
I think so. |
This PR fixes the conversion from
u32
toc_int
which resulted in negativec_int
values for bigu32
values.I'm a new contributor to Winit and I honestly didn't check all the guidelines nor I understand all the code, but I think I found a bug while investigating a bug in Bevy, which uses Winit: bevyengine/bevy#8948 (comment)
In short, when using
set_max_inner_size
orwith_max_inner_size
with a big value (for Bevy we use af32
logical size but I believe it's simply converted to au32
down the line), the max constraint end up being equal to the min one (making the window not resizeable, to the size of the min constraint). After testing, the threshold value for this to happen seem to be aroundu32::MAX / 2
(more or less, not sure why not exactly that but can be rounding errors), which seem to indicate a conversion to a signed int that would make the value negative somewhere.After investigating in Winit's code, I found conversions from
u32
toc_int
, and after testing in the playground it seems to be what's wrong: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=be9b6b0416fbb79ff0935ae4300036c7I'm not sure how to test stuff with Winit alone so I didn't test my changes, but they seem minor enough to not be a problem, hopefully?