Skip to content

Commit

Permalink
do not set cursor grab on window creation if not asked for (bevyengin…
Browse files Browse the repository at this point in the history
…e#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 bevyengine#3617 which was lost in bevyengine#6218
  • Loading branch information
mockersf authored and ItsDoot committed Feb 1, 2023
1 parent f1721a2 commit df43a1f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::converters::convert_cursor_grab_mode;
use bevy_math::{DVec2, IVec2};
use bevy_utils::HashMap;
use bevy_window::{
MonitorSelection, RawHandleWrapper, Window, WindowDescriptor, WindowId, WindowMode,
CursorGrabMode, MonitorSelection, RawHandleWrapper, Window, WindowDescriptor, WindowId,
WindowMode,
};
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use winit::{
Expand Down Expand Up @@ -161,11 +162,14 @@ impl WinitWindows {
}
}

match winit_window
.set_cursor_grab(convert_cursor_grab_mode(window_descriptor.cursor_grab_mode))
{
Ok(_) | Err(winit::error::ExternalError::NotSupported(_)) => {}
Err(err) => Err(err).unwrap(),
// 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 {
match winit_window
.set_cursor_grab(convert_cursor_grab_mode(window_descriptor.cursor_grab_mode))
{
Ok(_) | Err(winit::error::ExternalError::NotSupported(_)) => {}
Err(err) => Err(err).unwrap(),
}
}

winit_window.set_cursor_visible(window_descriptor.cursor_visible);
Expand Down

0 comments on commit df43a1f

Please sign in to comment.