Skip to content

[Merged by Bors] - fix cursor grab issue - #7010

Closed
VitalyAnkh wants to merge 2 commits into
bevyengine:mainfrom
VitalyAnkh:fix_cursor_grab
Closed

VitalyAnkh wants to merge 2 commits into
bevyengine:mainfrom
VitalyAnkh:fix_cursor_grab

Conversation

@VitalyAnkh

@VitalyAnkh VitalyAnkh commented Dec 23, 2022 •

Copy link
Copy Markdown
Contributor

Objective

Solution

  • Set the cursor grab mode after the window is built.

@VitalyAnkh

Copy link
Copy Markdown
Contributor Author

Oh no this doesn't solve the problem... The crash only happens on x11 platform for me, and it's always OK on wayland platform. This change doesn't make a difference.

@VitalyAnkh
VitalyAnkh marked this pull request as draft December 23, 2022 09:50
@VitalyAnkh
VitalyAnkh marked this pull request as ready for review December 23, 2022 10:40
@VitalyAnkh

Copy link
Copy Markdown
Contributor Author

This should work now.

@mockersf

Copy link
Copy Markdown
Member

Sorry, I missed your PR, I just saw the original issue title and went "oh right, we only fixed that at update time, not at creation time"

I can't test on Linux, I'll trust you if you say it's just an issue of it needed to being delayed.

Fallback should still be added for Windows and macOS support.

@VitalyAnkh

Copy link
Copy Markdown
Contributor Author

The fallback logic should be already in our codebase:

bevy_window::CursorGrabMode::Confined => window
since the new setting cursor grab logic in bevy::window::Window::create_window invokes bevy::window::Window::set_cursor_grab which is actually a wrapper of
bevy_winit::change_window in the above.

This also eliminates code duplicate 😃.

@nicopap nicopap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm it fixes #7007 .

}

/// Map [`bevy_window::CursorGrabMode`] to [`winit::window::CursorGrabMode`].
pub fn convert_cursor_grab_mode(mode: CursorGrabMode) -> winit::window::CursorGrabMode {

@nicopap nicopap Dec 23, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is non-blocking but I'm going to Chesterton-fence you here: What purpose did this serve? I notice it is marked pub so technically this is breaking change. Though such a conversion method defined as a free function is really weird.

@VitalyAnkh VitalyAnkh Dec 23, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for bevy crates' internal usage. I introduced this function for bevy_window abstracts its own CursorGrabMode struct because bevy_window doesn't want to depend on winit, then bevy_winit should convert bevy_window's CursorGrabMode to winit::window::CursorGrabMode. I think this function shouldn't be pub but I just followed these conversion functions' signature above. Anyway, we could remove it now and it shouldn't break much code since it's not intended for end users in the beginning. If this breaks the semantic version, please help us find a way to get of it... Sorry for this mistake.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry. This is perfectly fine.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a public module so this isn't a breaking change.

Comment thread examples/window/window_settings.rs Outdated
height: 300.,
present_mode: PresentMode::AutoVsync,
always_on_top: true,
cursor_grab_mode: CursorGrabMode::Confined,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the example here need to be changed? Feels like this just adds noise to the example without an explanation why users should set this. If it should, we should document what this is actually doing so that people learning from the example can improve their understanding.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to show users they could set cursor grab mode directly. But they will do this without guidance since this field is already in WindowDescriptor. I will remove this change. Thanks!

@james7132 james7132 added C-Bug An unexpected or incorrect behavior A-Windowing Platform-agnostic interface layer to run your app in I-Crash A sudden unexpected crash O-Linux Specific to the Linux desktop operating system C-Startup A crash that occurs when first attempting to run a Bevy app labels Dec 24, 2022
@james7132 james7132 added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Dec 26, 2022
);
// Do not set the grab mode on window creation if it's none, this can fail on mobile
if window_descriptor.cursor_grab_mode != CursorGrabMode::None {
window.set_cursor_grab_mode(window_descriptor.cursor_grab_mode);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer if this still logged an error here, so the user gets some feedback rather than silently failing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply. I'm experiencing covid-19 this week.

Like the fallback will be done in bevy_winit::change_window, the errors, if any, will also be logged there:

.unwrap_or_else(|e| error!("Unable to un/grab cursor: {}", e));
.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh gotcha nvm, my brain was in windows as entities mode and I forgot we had window commands

@IceSentry IceSentry left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't experience the bug, so can't confirm if it's fixed, but the code makes sense to me and mouse grabbing still works as expected for me.

@james7132 james7132 added this to the 0.10 milestone Jan 4, 2023
@cart

cart commented Jan 4, 2023

Copy link
Copy Markdown
Member

bors r+

bors Bot pushed a commit that referenced this pull request Jan 4, 2023
# Objective

- Set the cursor grab mode after the window is built, fix #7007, clean some conversion code.

## Solution

- Set the cursor grab mode after the window is built.
@bors bors Bot changed the title fix cursor grab issue [Merged by Bors] - fix cursor grab issue Jan 4, 2023
@bors bors Bot closed this Jan 4, 2023
alradish pushed a commit to alradish/bevy that referenced this pull request Jan 22, 2023
# Objective

- Set the cursor grab mode after the window is built, fix bevyengine#7007, clean some conversion code.

## Solution

- Set the cursor grab mode after the window is built.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

- Set the cursor grab mode after the window is built, fix bevyengine#7007, clean some conversion code.

## Solution

- Set the cursor grab mode after the window is built.
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 C-Startup A crash that occurs when first attempting to run a Bevy app I-Crash A sudden unexpected crash O-Linux Specific to the Linux desktop operating system S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CursorGrabMode::Confined on Linux panicks on startup

7 participants