Skip to content

Commit

Permalink
do not set cursor grab on window creation if not asked for (#3617)
Browse files Browse the repository at this point in the history
# Objective

- 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
```
[Error] Unhandled Promise Rejection: TypeError: getObject(arg0).exitPointerLock is not a function. (In 'getObject(arg0).exitPointerLock()', 'getObject(arg0).exitPointerLock' is undefined)
    (anonymous function) (rect.js:1089)
    wasm-stub
    <?>.wasm-function[web_sys::features::gen_Document::Document::exit_pointer_lock::h20ffc49be163fc45]
    <?>.wasm-function[winit::platform_impl::platform::backend::canvas::Canvas::set_cursor_grab::h6a9472cf55263e98]
    <?>.wasm-function[bevy_winit::winit_windows::WinitWindows::create_window::h9db5b3cbb24347c5]
    <?>.wasm-function[<bevy_winit::WinitPlugin as bevy_app::plugin::Plugin>::build::ha4a7c046b80c4280]
    <?>.wasm-function[bevy_app::plugin_group::PluginGroupBuilder::finish::h0e5bc78f71c37b2f]
    <?>.wasm-function[rect::main::h899852fd17f2d489]
    <?>.wasm-function[std::sys_common::backtrace::__rust_begin_short_backtrace::hfe38f282e8dda96b]
    <?>.wasm-function[std::rt::lang_start::{{closure}}::hc2f3b555ffc58618]
    <?>.wasm-function[std::rt::lang_start_internal::ha901ae30d88554f2]
    <?>.wasm-function[main]
    <?>.wasm-function[]
    wasm-stub
    21261
    (anonymous function) (rect.js:1664)
    asyncFunctionResume
    (anonymous function)
    promiseReactionJobWithoutPromise
    promiseReactionJob
```

## Solution

- Do not call the api to release cursor grab on window creation, as the cursor is not grabbed anyway at this point
  • Loading branch information
mockersf committed Jan 15, 2022
1 parent 2186eae commit c16d0c5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ impl WinitWindows {

let winit_window = winit_window_builder.build(event_loop).unwrap();

match winit_window.set_cursor_grab(window_descriptor.cursor_locked) {
Ok(_) => {}
Err(winit::error::ExternalError::NotSupported(_)) => {}
Err(err) => Err(err).unwrap(),
if window_descriptor.cursor_locked {
match winit_window.set_cursor_grab(true) {
Ok(_) => {}
Err(winit::error::ExternalError::NotSupported(_)) => {}
Err(err) => Err(err).unwrap(),
}
}

winit_window.set_cursor_visible(window_descriptor.cursor_visible);
Expand Down

2 comments on commit c16d0c5

@cryscan
Copy link
Contributor

Choose a reason for hiding this comment

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

As per https://github.com/rust-windowing/winit/blob/master/FEATURES.md, cursor grab on WASM has just been implemented since winit 0.26.1. As Bevy 0.6 uses 0.26.0 though, is it possible to bump the version in future releases?

@mockersf
Copy link
Member Author

Choose a reason for hiding this comment

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

@cryscan as 0.26.1 is semver compatible with 0.26.0, Bevy will use the latest one. You can run cargo update locally to update your lockfile

Please sign in to comment.