Skip to content

Properly handle repeated window close requests#14573

Merged
alice-i-cecile merged 1 commit intobevyengine:mainfrom
Brezak:repeated-window-close-crash
Aug 1, 2024
Merged

Properly handle repeated window close requests#14573
alice-i-cecile merged 1 commit intobevyengine:mainfrom
Brezak:repeated-window-close-crash

Conversation

@Brezak
Copy link
Contributor

@Brezak Brezak commented Aug 1, 2024

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::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:

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.

@Brezak Brezak force-pushed the repeated-window-close-crash branch from 8394aee to 4c32750 Compare August 1, 2024 16:06
@Brezak Brezak force-pushed the repeated-window-close-crash branch from 4c32750 to c6d1e60 Compare August 1, 2024 16:07
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior D-Trivial Nice and easy! A great choice to get started with Bevy A-Windowing Platform-agnostic interface layer to run your app in S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Aug 1, 2024
@alice-i-cecile alice-i-cecile added this to the 0.14.1 milestone Aug 1, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Aug 1, 2024
Merged via the queue into bevyengine:main with commit 0c7df88 Aug 1, 2024
@Brezak Brezak deleted the repeated-window-close-crash branch August 1, 2024 17:08
mockersf pushed a commit that referenced this pull request Aug 2, 2024
# 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::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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants