diff --git a/crates/bevy_winit/src/system.rs b/crates/bevy_winit/src/system.rs index 6348f050ad..f46f0b06ca 100644 --- a/crates/bevy_winit/src/system.rs +++ b/crates/bevy_winit/src/system.rs @@ -385,8 +385,11 @@ pub(crate) fn changed_windows( } } - if window.cursor_options.grab_mode != cache.window.cursor_options.grab_mode { - crate::winit_windows::attempt_grab(winit_window, window.cursor_options.grab_mode); + if window.cursor_options.grab_mode != cache.window.cursor_options.grab_mode + && crate::winit_windows::attempt_grab(winit_window, window.cursor_options.grab_mode) + .is_err() + { + window.cursor_options.grab_mode = cache.window.cursor_options.grab_mode; } if window.cursor_options.visible != cache.window.cursor_options.visible { diff --git a/crates/bevy_winit/src/winit_windows.rs b/crates/bevy_winit/src/winit_windows.rs index c4d76aa084..ff08b20b40 100644 --- a/crates/bevy_winit/src/winit_windows.rs +++ b/crates/bevy_winit/src/winit_windows.rs @@ -10,6 +10,7 @@ use bevy_window::{ use winit::{ dpi::{LogicalSize, PhysicalPosition}, + error::ExternalError, event_loop::ActiveEventLoop, monitor::{MonitorHandle, VideoModeHandle}, window::{CursorGrabMode as WinitCursorGrabMode, Fullscreen, Window as WinitWindow, WindowId}, @@ -279,7 +280,7 @@ impl WinitWindows { // Do not set the grab mode on window creation if it's none. It can fail on mobile. if window.cursor_options.grab_mode != CursorGrabMode::None { - attempt_grab(&winit_window, window.cursor_options.grab_mode); + let _ = attempt_grab(&winit_window, window.cursor_options.grab_mode); } winit_window.set_cursor_visible(window.cursor_options.visible); @@ -380,7 +381,10 @@ pub fn get_best_videomode(monitor: &MonitorHandle) -> VideoModeHandle { modes.first().unwrap().clone() } -pub(crate) fn attempt_grab(winit_window: &WinitWindow, grab_mode: CursorGrabMode) { +pub(crate) fn attempt_grab( + winit_window: &WinitWindow, + grab_mode: CursorGrabMode, +) -> Result<(), ExternalError> { let grab_result = match grab_mode { CursorGrabMode::None => winit_window.set_cursor_grab(WinitCursorGrabMode::None), CursorGrabMode::Confined => winit_window @@ -398,6 +402,9 @@ pub(crate) fn attempt_grab(winit_window: &WinitWindow, grab_mode: CursorGrabMode }; bevy_utils::tracing::error!("Unable to {} cursor: {}", err_desc, err); + Err(err) + } else { + Ok(()) } }