Skip to content

Window.cursor_position can return Some when it shouldn't #8840

@Plonq

Description

@Plonq

Bevy version

0.10.1

What you did

Called the Window.cursor_position method after moving mouse from one window to another.

What went wrong

It intermittently returns Some(...) when it should be None.

Additional information

Using the small app below, this video shows the issue clearly. You can see that sometimes, but not always, when moving the cursor from one window directly to another window, the first window still thinks it has the cursor. This results in multiple windows claiming they have the cursor, while only one can at any one time.

I can see here Bevy sets the cursor position to None when it sees a WindowEvent::CursorLeft event from winit, but I verified that it is fired every time, even when the issue occurs, so I don't believe this is a bug in winit.

Screen.Recording.2023-06-14.at.7.26.15.pm.mov

Minimal app:

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(WindowPlugin {
            primary_window: Some(Window {
                position: WindowPosition::At(IVec2::new(400, 200)),
                ..default()
            }),
            ..default()
        }))
        .add_startup_system(setup)
        .add_system(print_cursor_position)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Window {
        title: "Second window".to_owned(),
        position: WindowPosition::At(IVec2::new(0, 0)),
        ..default()
    });
}

fn print_cursor_position(windows_q: Query<&Window>) {
    for window in windows_q.iter() {
        println!(
            "Window '{}' cursor position: {:?}",
            window.title,
            window.cursor_position()
        );
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WindowingPlatform-agnostic interface layer to run your app inC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions