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

Setting cursor grab mode causes errors to be printed with no way to handle it #6590

Closed
IceSentry opened this issue Nov 13, 2022 · 6 comments
Closed
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior
Milestone

Comments

@IceSentry
Copy link
Contributor

Bevy version

0.9 and latest

What you did

Ran the mouse_grab example.

What went wrong

When pressing the left button, winit does successfully set the grab mode, but bevy prints an error message:

ERROR bevy_winit: Unable to un/grab cursor: the requested operation is not supported by Winit

In the example this happens only once because it's behind a condition, but if you run it unconditionally in a system it will print this every frame even when the cursor is clearly locked/unlocked. In other words the feature clearly is supported yet winit reports an error.

The main issue here is that we can't get the result from winit and handle it user side. Ignoring the error in bevy wouldn't be ideal either, but that means an unavoidable error message for anyone that uses this api.

Relevant system information

Windows 10

@IceSentry IceSentry added C-Bug An unexpected or incorrect behavior A-Windowing Platform-agnostic interface layer to run your app in labels Nov 13, 2022
@IceSentry
Copy link
Contributor Author

After a bit more investigation, it seems to be that CursorGrabMode::Locked is not supported, but CursorGrabMode::Confined is. This should probably be documented somewhere since it seems it falls back to Confined when Locked isn't supported but it still reports it as Locked when using window.cursor_grab_mode()

@BlackPhlox
Copy link
Contributor

BlackPhlox commented Nov 13, 2022

Yeah, the un/grab is now an enum, and I think that CursorGrabMode::Locked is not supported for winit as of yet, we should change it to Confined for the moment
Edit: Currently not supported for Windows nor IOS / Android

@alice-i-cecile alice-i-cecile added this to the 0.9.1 milestone Nov 13, 2022
@IceSentry
Copy link
Contributor Author

IceSentry commented Nov 13, 2022

To add a bit more detail, CursorGrabMode::Locked is supported in macOS but not Windows, CursorGrabMode::Confined is supported by windows but not macOS. On windows setting it to Locked will silently treat it as Confined and spam the error message but keep working correctly and report it as CursorGrabMode::Locked even if internally it isn't using it.

We should at least document this behaviour.

@BlackPhlox
Copy link
Contributor

BlackPhlox commented Nov 13, 2022

CursorGrabMode Locked and Confined works almost functionally the same. It is only relevant if you wanna see the mouse and or when you ungrab that determines the mouse position. I would put this at warning log-level at most and include that it does a fallback in the message.

@alice-i-cecile
Copy link
Member

Punting to 0.10 as I'm unsure how to solve this effectively.

@IceSentry
Copy link
Contributor Author

IceSentry commented Nov 25, 2022

My current fix is semver compatible and uses the recommended approach from winit so it could be in 0.9.1. At the very least I think we should update the docs to explain the issue and maybe add a snippet to show how to make it cross platform.

@alice-i-cecile alice-i-cecile modified the milestones: 0.10, 0.9.1 Nov 25, 2022
@bors bors bot closed this as completed in 17b7025 Nov 26, 2022
cart pushed a commit that referenced this issue Nov 30, 2022
…error (#6599)

# Objective

- Closes #6590
- The grab mode is platform dependent, this is problematic for bevy users since we can't easily use the recommended way to detect if the feature works like the winit docs recommend https://docs.rs/winit/0.27.5/winit/window/struct.Window.html#method.set_cursor_grab

## Solution

Try to use the grab mode that was requested, if it fails use the other one. Only then log an error if it fails after this step.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
…error (bevyengine#6599)

# Objective

- Closes bevyengine#6590
- The grab mode is platform dependent, this is problematic for bevy users since we can't easily use the recommended way to detect if the feature works like the winit docs recommend https://docs.rs/winit/0.27.5/winit/window/struct.Window.html#method.set_cursor_grab

## Solution

Try to use the grab mode that was requested, if it fails use the other one. Only then log an error if it fails after this step.
Subserial pushed a commit to Subserial/bevy_winit_hook that referenced this issue Jan 24, 2024
…error (#6599)

# Objective

- Closes bevyengine/bevy#6590
- The grab mode is platform dependent, this is problematic for bevy users since we can't easily use the recommended way to detect if the feature works like the winit docs recommend https://docs.rs/winit/0.27.5/winit/window/struct.Window.html#method.set_cursor_grab

## Solution

Try to use the grab mode that was requested, if it fails use the other one. Only then log an error if it fails after this step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior
Projects
None yet
3 participants