Skip to content

Commit

Permalink
Fix example return_after_run (bevyengine#1082)
Browse files Browse the repository at this point in the history
* ignore error when setting global tracing subscriber

* ignore unfocus event on window closed previously

* update example to show how to disable LogPlugin
  • Loading branch information
mockersf authored Dec 18, 2020
1 parent 596bed8 commit d0840bd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
8 changes: 4 additions & 4 deletions crates/bevy_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ impl Plugin for LogPlugin {
app.resources_mut().insert_thread_local(guard);
let subscriber = subscriber.with(chrome_layer);
bevy_utils::tracing::subscriber::set_global_default(subscriber)
.expect("Could not set global default tracing subscriber.");
.expect("Could not set global default tracing subscriber. If you've already set up a tracing subscriber, please disable LogPlugin from Bevy's DefaultPlugins");
}

#[cfg(not(feature = "tracing-chrome"))]
{
bevy_utils::tracing::subscriber::set_global_default(subscriber)
.expect("Could not set global default tracing subscriber.");
.expect("Could not set global default tracing subscriber. If you've already set up a tracing subscriber, please disable LogPlugin from Bevy's DefaultPlugins");
}
}

Expand All @@ -91,14 +91,14 @@ impl Plugin for LogPlugin {
tracing_wasm::WASMLayerConfig::default(),
));
bevy_utils::tracing::subscriber::set_global_default(subscriber)
.expect("Could not set global default tracing subscriber.");
.expect("Could not set global default tracing subscriber. If you've already set up a tracing subscriber, please disable LogPlugin from Bevy's DefaultPlugins");
}

#[cfg(target_os = "android")]
{
let subscriber = subscriber.with(android_tracing::AndroidLayer::default());
bevy_utils::tracing::subscriber::set_global_default(subscriber)
.expect("Could not set global default tracing subscriber.");
.expect("Could not set global default tracing subscriber. If you've already set up a tracing subscriber, please disable LogPlugin from Bevy's DefaultPlugins");
}
}
}
18 changes: 13 additions & 5 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,19 @@ pub fn winit_runner(mut app: App) {
let mut focused_events =
app.resources.get_mut::<Events<WindowFocused>>().unwrap();
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
let window_id = winit_windows.get_window_id(winit_window_id).unwrap();
focused_events.send(WindowFocused {
id: window_id,
focused,
});
match (winit_windows.get_window_id(winit_window_id), focused) {
(Some(window_id), _) => focused_events.send(WindowFocused {
id: window_id,
focused,
}),
// unfocus event for an unknown window, ignore it
(None, false) => (),
// focus event on an unknown window, this is an error
_ => panic!(
"Focused(true) event on unknown window {:?}",
winit_window_id
),
}
}
_ => {}
},
Expand Down
14 changes: 13 additions & 1 deletion examples/app/return_after_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@ fn main() {
})
.add_resource(ClearColor(Color::rgb(0.2, 0.2, 0.8)))
.add_plugins(DefaultPlugins)
.add_system(system1.system())
.run();
println!("Running another App.");
App::build()
.add_resource(WinitConfig {
return_from_run: true,
})
.add_resource(ClearColor(Color::rgb(0.2, 0.8, 0.2)))
.add_plugins(DefaultPlugins)
.add_plugins_with(DefaultPlugins, |group| {
group.disable::<bevy::log::LogPlugin>()
})
.add_system(system2.system())
.run();
println!("Done.");
}

fn system1() {
info!("logging from first app");
}

fn system2() {
info!("logging from second app");
}

0 comments on commit d0840bd

Please sign in to comment.