Skip to content

[MacOS] [Safari/Wasm] Window::cursor_position returns None when inside the window on MouseButtonInput Released #12870

Open
@extrawurst

Description

@extrawurst

Bevy version

tried with vanilla 0.13.1

Relevant system information

cargo/rust: 1.77
Safari: 17.4.1

What you did

altered one the bevy mouse button events examples:

use bevy::{input::mouse::MouseButtonInput, prelude::*};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Update, print_mouse_events_system)
        .run();
}

fn print_mouse_events_system(
    mut mouse_motion_events: EventReader<MouseButtonInput>,
    window: Query<&Window>,
) {
    for event in mouse_motion_events.read() {
        if let Ok(w) = window.get(event.window) {
            info!(
                "mouse button: {:?} cursor_position: {:?}",
                event.state,
                w.cursor_position()
            );
        }
    }
}

What went wrong

on Safari it does not allow getting the cursor_position from the window in the frame the mousebutton is released, seen in the log:

[Log] INFO src/main.rs:16 mouse button: Pressed cursor_position: Some(Vec2(441.0, 485.0)) (wasm_window_bug-8c728a0687bf9c77.js, line 489)
[Log] INFO src/main.rs:16 mouse button: Released cursor_position: None (wasm_window_bug-8c728a0687bf9c77.js, line 489)

on chrome and firefox when clicking (button down/up) inside the canvas it prints (as expected):

INFO src/main.rs:16 mouse button: Pressed cursor_position: Some(Vec2(566.0, 305.0)) wasm_window_bug-8c728a0687bf9c77.js:489:21
INFO src/main.rs:16 mouse button: Released cursor_position: Some(Vec2(566.0, 305.0)) wasm_window_bug-8c728a0687bf9c77.js:489:21

Additional information

I assume its a bug in bevy_winit or winit itself, but i did not drill deeper yet

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WindowingPlatform-agnostic interface layer to run your app inC-BugAn unexpected or incorrect behaviorO-MacOSSpecific to the MacOS (Apple) desktop operating systemO-WebSpecific to web (WASM) builds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions