bevy/crates/bevy_window/src
Brezak 3a6176b6cb
Properly handle repeated window close requests (#14573)
# Objective

Spamming the window close button on window may trigger a panic.

```
thread 'main' panicked at <Bevy repo>\crates\bevy_ecs\src\system\commands\mod.rs:1320:13:
error[B0003]: Could not insert a bundle (of type `bevy_window:🪟:ClosingWindow`) for entity 0v1#4294967296 because it doesn't exist in this World. See: https://bevyengine.org/learn/errors/b0003
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic when applying buffers for system `bevy_window::system::close_when_requested`!
2024-08-01T15:00:29.742612Z  WARN bevy_ecs::world::command_queue: CommandQueue has un-applied commands being dropped. Did you forget to call SystemState::apply?
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
error: process didn't exit successfully: `target\debug\bevy.exe` (exit code: 101)
```

## Solution

Don't panic when trying to insert the `ClosingWindow` component into a
entity.

## Testing

Found and tested on windows. I haven't checked if this bug happens on
linux or macos.
For testing I ran this code:

```rust
use std::{thread, time::Duration};

use bevy::prelude::*;

fn lag() {
    thread::sleep(Duration::from_millis(300));
}

fn main() -> AppExit {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Update, lag)
        .run()
}
```

Then spammed the window close button. The panic no longer occurs.
2024-08-02 19:26:47 +02:00
..
cursor.rs Update cursor.rs (#11617) 2024-01-30 16:34:17 +00:00
event.rs fix: upgrade to winit v0.30 (#13366) 2024-06-03 13:06:48 +00:00
lib.rs fix: upgrade to winit v0.30 (#13366) 2024-06-03 13:06:48 +00:00
raw_handle.rs fix: upgrade to winit v0.30 (#13366) 2024-06-03 13:06:48 +00:00
system.rs Properly handle repeated window close requests (#14573) 2024-08-02 19:26:47 +02:00
window.rs apply window scale to window size when creating it (#13967) 2024-06-21 20:27:55 +02:00