bevyengine / bevyengine/bevy

Adjust Window(Winit) Close Timing AppExit event

Open
#6,215 2 comments 0 reactions 0 assignees View on GitHub
A-App C-Usability
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

# Objective
Adjust the timing sooner for AppExit event being raised after the Window "X" button is pressed or close_on_esc fires. Currently, the AppExit event is raised between stages of CoreStage::PostUpdate and CoreStage::Last.

## Solution

1. I believe the source of the AppExit message begins here: [crates/bevy_winit/src/lib.rs](https://github.com/bevyengine/bevy/blob/main/crates/bevy_winit/src/lib.rs#L422). I have little to no experience with bevy internals and I am unsure of what happens after Winit::CloseRequested turns into Bevy::WindowCloseRequested and before it turns into an AppExit event.
2. AppExit documentation could be rewritten to recommend placing systems which listen for this event in CoreStage::Last. Some variant of :

```
An event that indicates the App should exit. This will fully exit the app process at the start of the next tick of the schedule.

You can also use this event to detect that an exit was requested. In order to receive it, systems subscribing to this event should run after it was emitted and before the schedule of the same frame is over.

The earliest this should happen is in CoreStage::Last.
```

### Remarks
Issue opened per request of Alice on discord.

Contributor guide

Open the contributing guide

Research direction

Start by reading crates/bevy_winit/src/lib.rs around line 422 and trace the issue's described path from Winit::CloseRequested through Bevy::WindowCloseRequested to AppExit. Review the AppExit documentation and CoreStage::Last scheduling behavior. Done means the timing is adjusted as requested or the documentation clearly records the supported timing and listener placement.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.