Skip to content

Commit 8122b35

Browse files
authored
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 283654c commit 8122b35

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
@@ -431,6 +431,13 @@ impl<T: Event> ApplicationHandler<T> for WinitAppRunnerState<T> {
431431
}
432432
WindowEvent::RedrawRequested => {
433433
self.ran_update_since_last_redraw = false;
434+
435+
// https://github.com/bevyengine/bevy/issues/17488
436+
#[cfg(target_os = "windows")]
437+
{
438+
self.redraw_requested = true;
439+
self.redraw_requested(_event_loop);
440+
}
434441
}
435442
_ => {}
436443
}
@@ -468,6 +475,27 @@ impl<T: Event> ApplicationHandler<T> for WinitAppRunnerState<T> {
468475
create_windows(event_loop, create_window.get_mut(self.world_mut()));
469476
create_window.apply(self.world_mut());
470477

478+
// TODO: This is a workaround for https://github.com/bevyengine/bevy/issues/17488
479+
// while preserving the iOS fix in https://github.com/bevyengine/bevy/pull/11245
480+
// The monitor sync logic likely belongs in monitor event handlers and not here.
481+
#[cfg(not(target_os = "windows"))]
482+
self.redraw_requested(event_loop);
483+
}
484+
485+
fn suspended(&mut self, _event_loop: &ActiveEventLoop) {
486+
// Mark the state as `WillSuspend`. This will let the schedule run one last time
487+
// before actually suspending to let the application react
488+
self.lifecycle = AppLifecycle::WillSuspend;
489+
}
490+
491+
fn exiting(&mut self, _event_loop: &ActiveEventLoop) {
492+
let world = self.world_mut();
493+
world.clear_all();
494+
}
495+
}
496+
497+
impl<T: Event> WinitAppRunnerState<T> {
498+
fn redraw_requested(&mut self, event_loop: &ActiveEventLoop) {
471499
let mut redraw_event_reader = EventCursor::<RequestRedraw>::default();
472500

473501
let mut focused_windows_state: SystemState<(Res<WinitSettings>, Query<(Entity, &Window)>)> =
@@ -662,19 +690,6 @@ impl<T: Event> ApplicationHandler<T> for WinitAppRunnerState<T> {
662690
}
663691
}
664692

665-
fn suspended(&mut self, _event_loop: &ActiveEventLoop) {
666-
// Mark the state as `WillSuspend`. This will let the schedule run one last time
667-
// before actually suspending to let the application react
668-
self.lifecycle = AppLifecycle::WillSuspend;
669-
}
670-
671-
fn exiting(&mut self, _event_loop: &ActiveEventLoop) {
672-
let world = self.world_mut();
673-
world.clear_all();
674-
}
675-
}
676-
677-
impl<T: Event> WinitAppRunnerState<T> {
678693
fn should_update(&self, update_mode: UpdateMode) -> bool {
679694
let handle_event = match update_mode {
680695
UpdateMode::Continuous => {

0 commit comments

Comments
 (0)