Skip to content

Commit 2eb2ecd

Browse files
Docs: App::run() might never return; effect of WinitSettings::return_from_run. (#7228)
# Objective See: - bevyengine/bevy#7067 (comment) - (This does not fully close that issue in my opinion.) - https://discord.com/channels/691052431525675048/1063454009769340989 ## Solution This merge request adds documentation: 1. Alert users to the fact that `App::run()` might never return and code placed after it might never be executed. 2. Makes `winit::WinitSettings::return_from_run` discoverable. 3. Better explains why `winit::WinitSettings::return_from_run` is discouraged and better links to up-stream docs. on that topic. 4. Adds notes to the `app/return_after_run.rs` example which otherwise promotes a feature that carries caveats. Furthermore, w.r.t `winit::WinitSettings::return_from_run`: - Broken links to `winit` docs are fixed. - Links now point to BOTH `EventLoop::run()` and `EventLoopExtRunReturn::run_return()` which are the salient up-stream pages and make more sense, taken together. - Collateral damage: "Supported platforms" heading; disambiguation of "run" → `App::run()`; links. ## Future Work I deliberately structured the "`run()` might not return" section under `App::run()` to allow for alternative patterns (e.g. `AppExit` event, `WindowClosed` event) to be listed or mentioned, beneath it, in the future.
1 parent 067d898 commit 2eb2ecd

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/winit_config.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,28 @@ use bevy_utils::Duration;
44
/// A resource for configuring usage of the `rust_winit` library.
55
#[derive(Debug, Resource)]
66
pub struct WinitSettings {
7-
/// Configures the winit library to return control to the main thread after the
8-
/// [run](bevy_app::App::run) loop is exited. Winit strongly recommends avoiding this when
9-
/// possible. Before using this please read and understand the
10-
/// [caveats](winit::platform::run_return::EventLoopExtRunReturn::run_return) in the winit
11-
/// documentation.
7+
/// Configures `winit` to return control to the caller after exiting the
8+
/// event loop, enabling [`App::run()`](bevy_app::App::run()) to return.
129
///
13-
/// This feature is only available on desktop `target_os` configurations. Namely `windows`,
14-
/// `macos`, `linux`, `dragonfly`, `freebsd`, `netbsd`, and `openbsd`. If set to true on an
15-
/// unsupported platform [run](bevy_app::App::run) will panic.
10+
/// By default, [`return_from_run`](Self::return_from_run) is `false` and *Bevy*
11+
/// will use `winit`'s
12+
/// [`EventLoop::run()`](https://docs.rs/winit/latest/winit/event_loop/struct.EventLoop.html#method.run)
13+
/// to initiate the event loop.
14+
/// [`EventLoop::run()`](https://docs.rs/winit/latest/winit/event_loop/struct.EventLoop.html#method.run)
15+
/// will never return but will terminate the process after the event loop exits.
16+
///
17+
/// Setting [`return_from_run`](Self::return_from_run) to `true` will cause *Bevy*
18+
/// to use `winit`'s
19+
/// [`EventLoopExtRunReturn::run_return()`](https://docs.rs/winit/latest/winit/platform/run_return/trait.EventLoopExtRunReturn.html#tymethod.run_return)
20+
/// instead which is strongly discouraged by the `winit` authors.
21+
///
22+
/// # Supported platforms
23+
///
24+
/// This feature is only available on the following desktop `target_os` configurations:
25+
/// `windows`, `macos`, `linux`, `dragonfly`, `freebsd`, `netbsd`, and `openbsd`.
26+
///
27+
/// Setting [`return_from_run`](Self::return_from_run) to `true` on
28+
/// unsupported platforms will cause [`App::run()`](bevy_app::App::run()) to panic!
1629
pub return_from_run: bool,
1730
/// Configures how the winit event loop updates while the window is focused.
1831
pub focused_mode: UpdateMode,

0 commit comments

Comments
 (0)