Skip to content

Commit

Permalink
Fix return_after_run example (bevyengine#6420)
Browse files Browse the repository at this point in the history
# Objective

- Fixes  bevyengine#6311
- Make it clearer what should be done in the example (close the Bevy app window)

## Solution

- Remove the second windowed Bevy App [since winit does not support this](https://github.com/rust-windowing/winit/blob/v0.27.4/src/event_loop.rs#L82-L83)
- Add title to the Bevy window asking the user to close it

This is more of a quick fix to have a working example. It would be nicer if we had a small real usecase for this functionality.
Another alternativ that I tried out: If we want to showcase a second Bevy app as it was before, we could still do this as long as one of them does not have a window. But I don't see how this is helpful in the context of the example, so I stuck with only one Bevy app and a simple print afterwards.
  • Loading branch information
NiklasEi authored and ItsDoot committed Feb 1, 2023
1 parent 305106c commit 6a21a76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct WindowPlugin {
/// create 'headless' processes (processes without windows), which may
/// surprise your users. It is recommended to leave this setting as `true`.
///
/// If true, this plugin will add [`exit_on_all_closed`] to [`CoreStage::Update`].
/// If true, this plugin will add [`exit_on_all_closed`] to [`CoreStage::PostUpdate`].
pub exit_on_all_closed: bool,
/// Whether to close windows when they are requested to be closed (i.e.
/// when the close button is pressed).
Expand Down
31 changes: 11 additions & 20 deletions examples/app/return_after_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,24 @@
use bevy::{prelude::*, winit::WinitSettings};

fn main() {
println!("Running first App.");
println!("Running Bevy App");
App::new()
.insert_resource(WinitSettings {
return_from_run: true,
..default()
})
.insert_resource(ClearColor(Color::rgb(0.2, 0.2, 0.8)))
.add_plugins(DefaultPlugins)
.add_system(system1)
.run();
println!("Running another App.");
App::new()
.insert_resource(WinitSettings {
return_from_run: true,
.add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor {
title: "Close the window to return to the main function".to_owned(),
..default()
},
..default()
})
.insert_resource(ClearColor(Color::rgb(0.2, 0.8, 0.2)))
.add_plugins(DefaultPlugins.build().disable::<bevy::log::LogPlugin>())
.add_system(system2)
}))
.add_system(system)
.run();
println!("Done.");
}

fn system1() {
info!("logging from first app");
println!("Bevy App has exited. We are back in our main function.");
}

fn system2() {
info!("logging from second app");
fn system() {
info!("Logging from Bevy App");
}

0 comments on commit 6a21a76

Please sign in to comment.