bevy: 200-250ms lag on 'mouse down' events on macOS
Bevy version 0.8
Relevant system information
macOS Monterey
What you did
I found that mouse click events were delayed in my game.
Here is the example: https://github.com/bevyengine/bevy/blob/latest/examples/input/mouse_input.rs
What went wrong
To reproduce this, I ran the bare-bones bevy input example linked below, and get the same result. With some logging I found the delay for mouse down is consistently 200-250ms. However there is 0 delay for mouse up.
Additional information
Since delayed mouse input is a deal-breaker for the use of Bevy for me, I spent quite a white trying to reproduce this.
I created a bare-bones example using Winit (not bevy at all) and mouse down and mouse up are instant - no delay, so i do not think there is an issue there.
I replicated Bevy locally and started commenting things out to see if i could isolate the issue, and if i comment out the following, there is no delay, so i assume the culprit is in there somewhere:
https://github.com/bevyengine/bevy/blob/latest/crates/bevy_winit/src/lib.rs
Comment out the body of the event::Event::MainEventsCleared => {
match case, eg:
event::Event::MainEventsCleared => {
handle_create_window_events(
&mut app.world,
event_loop,
&mut create_window_event_reader,
);
let winit_config = app.world.resource::<WinitSettings>();
let update = if winit_state.active {
let windows = app.world.resource::<Windows>();
let focused = windows.iter().any(|w| w.is_focused());
match winit_config.update_mode(focused) {
UpdateMode::Continuous | UpdateMode::Reactive { .. } => true,
UpdateMode::ReactiveLowPower { .. } => {
winit_state.low_power_event
|| winit_state.redraw_request_sent
|| winit_state.timeout_reached
}
}
} else {
false
};
if update {
winit_state.last_update = Instant::now();
app.update();
}
}
Thanks for reading and thanks for the lovely game engine, I hope to be able to use it 😃
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (6 by maintainers)
Ok! I appear to have stumbled across the culprit: I run an app called ‘magnet’ on my macs that gives keyboard shortcuts for moving your windows around. For some reason, when this is running, i have the delay, and when it is not running, there is no delay. I’ll see if the developers of that app can fix it.
Here’s the app: https://apps.apple.com/au/app/magnet/id441258766?mt=12
I’m terribly sorry to have wasted your time!
nice to hear you found the source of the delay!
There is no problem on my platform:
rustc 1.63.0 (4b91a6ea7 2022-08-08)
If i revert all my comments in bevy_winit/src/lib.rs, thus use vanilla bevy, and instead put the following in my main.rs, the lag goes away:
However i’m fairly sure ReactiveLowPower isn’t what I want for an interactive game.
Thanks for responding! 😃 Just the default, as per https://github.com/bevyengine/bevy/blob/latest/examples/input/mouse_input.rs
-edit-
I believe the default is as follows: