bevyengine / bevyengine/bevy

Hang when resizing the window on Windows with an integrated graphics card

Open
#20,141 8 comments 1 reaction 0 assignees View on GitHub
A-Windowing C-Bug C-Machine-Specific I-Crash O-Windows S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version

Current `main` (8777dd414470284cd9653f94f405118f5576bf07).

## Relevant system information

Windows 11

## What you did

Ran a Bevy project and resized the window.

## What went wrong

While resizing the application window, the program freezes up completely and crashes. This problem occurs on every run but may take repeated resizing before it shows up. This is occurring in my application along with the basic Bevy 3d Scene example.

## Additional information

I bisected this and found the problem is introduced in 8122b35.

It seems like the issue is within `WinitAppRunnerState::about_to_wait()` where `self.redraw_requested(event_loop)` is always called for non-Windows platforms (where I assume the freezing does not occur), but there is unique, problematic logic for Windows that is causing `self.redraw_requested(event_loop)` to NOT be called enough.

The code causing this resize crash is also causing at least one related problem (and possibly others). See #19030 and my related PR #19772 where there is a freeze occurring during drag-and-drop events—the PR fix just ensures that `self.redraw_requested(event_loop)` runs during a drag-and-drop event.

This issue (along with #19030) can be fixed with the following code changes. That said, **I'm not familiar with the reasons for the current code, and this may cause other problems that the existing Windows-specific code was meant to fix.**

Other related issues per code comments: #17488 and #18027.

`bevy_winit/src/state.rs` lines 457-469
- Just comment out the Windows block
```rust
WindowEvent::RedrawRequested => {
self.ran_update_since_last_redraw = false;

// // https://github.com/bevyengine/bevy/issues/17488
// #[cfg(target_os = "windows")]
// {
// // Have the startup behavior run in about_to_wait, which prevents issues with
// // invisible window creation. https://github.com/bevyengine/bevy/issues/18027
// if self.startup_forced_updates == 0 {
// manual_run_redraw_requested = true;
// }
// }
}
```

`bevy_winit/src/state.rs` lines 519-539
- Comment out the Windows block and replace it with just calling `self.redraw_requested(event_loop)` like occurs on non-Windows platforms
```rust
// // Have the startup behavior run in about_to_wait, which prevents issues with
// // invisible window creation. https://github.com/bevyengine/bevy/issues/18027
// #[cfg(target_os = "windows")]
// {
// WINIT_WINDOWS.with_borrow(|winit_windows| {
// let headless = winit_windows.windows.is_empty();
// let exiting = self.app_exit.is_some();
// let reactive = matches!(self.update_mode, UpdateMode::Reactive { .. });
// let all_invisible = winit_windows
// .windows
// .iter()
// .all(|(_, w)| !w.is_visible().unwrap_or(false));
// if !exiting
// && (self.startup_forced_updates > 0 || headless || all_invisible || reactive)
// {
// self.redraw_requested(event_loop);
// }
// });
// }
self.redraw_requested(event_loop);
```

# Example of Crash
https://github.com/user-attachments/assets/aef8397b-3f10-4fc1-82c4-37a029d6a5b8

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.