Skip to content

Commit ca82fa8

Browse files
committed
do not set cursor grab on window creation if not asked for (#6381)
# Objective - Bevy main crashs on Safari mobile - On Safari mobile, calling winit_window.set_cursor_grab(true) fails as the API is not implemented (as there is no cursor on Safari mobile, the api doesn't make sense there). I don't know about other mobile browsers ## Solution - Do not call the api to release cursor grab on window creation, as the cursor is not grabbed anyway at this point - This is #3617 which was lost in #6218
1 parent bf6c457 commit ca82fa8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

crates/bevy_winit/src/winit_windows.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::converters::convert_cursor_grab_mode;
22
use bevy_math::{DVec2, IVec2};
33
use bevy_utils::HashMap;
44
use bevy_window::{
5-
MonitorSelection, RawHandleWrapper, Window, WindowDescriptor, WindowId, WindowMode,
5+
CursorGrabMode, MonitorSelection, RawHandleWrapper, Window, WindowDescriptor, WindowId,
6+
WindowMode,
67
};
78
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
89
use winit::{
@@ -161,11 +162,14 @@ impl WinitWindows {
161162
}
162163
}
163164

164-
match winit_window
165-
.set_cursor_grab(convert_cursor_grab_mode(window_descriptor.cursor_grab_mode))
166-
{
167-
Ok(_) | Err(winit::error::ExternalError::NotSupported(_)) => {}
168-
Err(err) => Err(err).unwrap(),
165+
// Do not set the grab mode on window creation if it's none, this can fail on mobile
166+
if window_descriptor.cursor_grab_mode != CursorGrabMode::None {
167+
match winit_window
168+
.set_cursor_grab(convert_cursor_grab_mode(window_descriptor.cursor_grab_mode))
169+
{
170+
Ok(_) | Err(winit::error::ExternalError::NotSupported(_)) => {}
171+
Err(err) => Err(err).unwrap(),
172+
}
169173
}
170174

171175
winit_window.set_cursor_visible(window_descriptor.cursor_visible);

0 commit comments

Comments
 (0)