Skip to content

Sending window events via the ECS doesn't update the corresponding fields on the Window. #6163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alice-i-cecile opened this issue Oct 4, 2022 · 3 comments
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior C-Testing A change that impacts how we test Bevy or how users test their apps

Comments

@alice-i-cecile
Copy link
Member

Bevy version

0.8.1

What you did

Sent a CursorMoved event, or another event from bevy_window.

What went wrong

The corresponding fields on the appropriate Window were not updated.

Additional information

This was discovered while attempting to get input playback working properly: Leafwing-Studios/leafwing_input_playback#10

Users can workaround this by manually setting the appropriate fields: https://docs.rs/bevy/latest/bevy/window/struct.Window.html#method.set_cursor_position. While it would be nice to have #4530 to make this pattern easier, simply adding a set of systems that runs at the start of each frame, reads these events and then sets the corresponding window fields would probably be enough to fix this surprising behavior.

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Windowing Platform-agnostic interface layer to run your app in C-Testing A change that impacts how we test Bevy or how users test their apps labels Oct 4, 2022
@mockersf
Copy link
Member

mockersf commented Oct 4, 2022

This is expected, events like CursorMoved are emitted by the window when it changes, not consumed by it.

Trying to use the mouse position both from events and from the window resource at the same time can never be trusted as the window resource will only show the state as of the latest event from winit. Any intermediate event won't have the same value.

@DJMcNab
Copy link
Member

DJMcNab commented Oct 4, 2022

To clarify, the correct way do this is to make your own custom runner which both updates the window fields and sends the events you need. That is, mock bevy_winit

@alice-i-cecile
Copy link
Member Author

Alright, I've managed to get this working without upstream changes. #4537 will make the strategy proposed by @DJMcNab much less painful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior C-Testing A change that impacts how we test Bevy or how users test their apps
Projects
None yet
Development

No branches or pull requests

3 participants