Skip to content

Commit 8628545

Browse files
aloucksmockersf
authored andcommitted
Fix window freezing when dragged or resized on Windows (#18004)
# Objective Fixes #17488 ## Solution The world update logic happened in the the `about_to_wait` winit window callback, but this is is not correct as (1) the winit documentation states that the callback should not be used for that purpose and (2) the callback is not fired when the window is resized or being dragged. However, that callback was used in #11245 to fix an iOS bug (which caused the regression). The solution presented here is a workaround until the event loop code can be re-written. ## Testing I confirmed that the `eased_motion` example continued to be animated when dragging or resizing the window. https://github.com/user-attachments/assets/ffaf0abf-4cd7-479b-83e9-e1850aaf3513
1 parent 3a6273b commit 8628545

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

crates/bevy_winit/src/state.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,13 @@ impl<T: Event> ApplicationHandler<T> for WinitAppRunnerState<T> {
411411
}
412412
WindowEvent::RedrawRequested => {
413413
self.ran_update_since_last_redraw = false;
414+
415+
// https://github.com/bevyengine/bevy/issues/17488
416+
#[cfg(target_os = "windows")]
417+
{
418+
self.redraw_requested = true;
419+
self.redraw_requested(_event_loop);
420+
}
414421
}
415422
_ => {}
416423
}
@@ -448,6 +455,27 @@ impl<T: Event> ApplicationHandler<T> for WinitAppRunnerState<T> {
448455
create_windows(event_loop, create_window.get_mut(self.world_mut()));
449456
create_window.apply(self.world_mut());
450457

458+
// TODO: This is a workaround for https://github.com/bevyengine/bevy/issues/17488
459+
// while preserving the iOS fix in https://github.com/bevyengine/bevy/pull/11245
460+
// The monitor sync logic likely belongs in monitor event handlers and not here.
461+
#[cfg(not(target_os = "windows"))]
462+
self.redraw_requested(event_loop);
463+
}
464+
465+
fn suspended(&mut self, _event_loop: &ActiveEventLoop) {
466+
// Mark the state as `WillSuspend`. This will let the schedule run one last time
467+
// before actually suspending to let the application react
468+
self.lifecycle = AppLifecycle::WillSuspend;
469+
}
470+
471+
fn exiting(&mut self, _event_loop: &ActiveEventLoop) {
472+
let world = self.world_mut();
473+
world.clear_all();
474+
}
475+
}
476+
477+
impl<T: Event> WinitAppRunnerState<T> {
478+
fn redraw_requested(&mut self, event_loop: &ActiveEventLoop) {
451479
let mut redraw_event_reader = EventCursor::<RequestRedraw>::default();
452480

453481
let mut focused_windows_state: SystemState<(Res<WinitSettings>, Query<(Entity, &Window)>)> =
@@ -642,19 +670,6 @@ impl<T: Event> ApplicationHandler<T> for WinitAppRunnerState<T> {
642670
}
643671
}
644672

645-
fn suspended(&mut self, _event_loop: &ActiveEventLoop) {
646-
// Mark the state as `WillSuspend`. This will let the schedule run one last time
647-
// before actually suspending to let the application react
648-
self.lifecycle = AppLifecycle::WillSuspend;
649-
}
650-
651-
fn exiting(&mut self, _event_loop: &ActiveEventLoop) {
652-
let world = self.world_mut();
653-
world.clear_all();
654-
}
655-
}
656-
657-
impl<T: Event> WinitAppRunnerState<T> {
658673
fn should_update(&self, update_mode: UpdateMode) -> bool {
659674
let handle_event = match update_mode {
660675
UpdateMode::Continuous => {

0 commit comments

Comments
 (0)