mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 22:20:20 +00:00
Fix example return_after_run (#1082)
* ignore error when setting global tracing subscriber * ignore unfocus event on window closed previously * update example to show how to disable LogPlugin
This commit is contained in:
parent
596bed8ce2
commit
d0840bd721
3 changed files with 30 additions and 10 deletions
|
@ -74,13 +74,13 @@ impl Plugin for LogPlugin {
|
||||||
app.resources_mut().insert_thread_local(guard);
|
app.resources_mut().insert_thread_local(guard);
|
||||||
let subscriber = subscriber.with(chrome_layer);
|
let subscriber = subscriber.with(chrome_layer);
|
||||||
bevy_utils::tracing::subscriber::set_global_default(subscriber)
|
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"))]
|
#[cfg(not(feature = "tracing-chrome"))]
|
||||||
{
|
{
|
||||||
bevy_utils::tracing::subscriber::set_global_default(subscriber)
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,14 +91,14 @@ impl Plugin for LogPlugin {
|
||||||
tracing_wasm::WASMLayerConfig::default(),
|
tracing_wasm::WASMLayerConfig::default(),
|
||||||
));
|
));
|
||||||
bevy_utils::tracing::subscriber::set_global_default(subscriber)
|
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")]
|
#[cfg(target_os = "android")]
|
||||||
{
|
{
|
||||||
let subscriber = subscriber.with(android_tracing::AndroidLayer::default());
|
let subscriber = subscriber.with(android_tracing::AndroidLayer::default());
|
||||||
bevy_utils::tracing::subscriber::set_global_default(subscriber)
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,11 +336,19 @@ pub fn winit_runner(mut app: App) {
|
||||||
let mut focused_events =
|
let mut focused_events =
|
||||||
app.resources.get_mut::<Events<WindowFocused>>().unwrap();
|
app.resources.get_mut::<Events<WindowFocused>>().unwrap();
|
||||||
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
|
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
|
||||||
let window_id = winit_windows.get_window_id(winit_window_id).unwrap();
|
match (winit_windows.get_window_id(winit_window_id), focused) {
|
||||||
focused_events.send(WindowFocused {
|
(Some(window_id), _) => focused_events.send(WindowFocused {
|
||||||
id: window_id,
|
id: window_id,
|
||||||
focused,
|
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
|
||||||
|
),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,6 +8,7 @@ fn main() {
|
||||||
})
|
})
|
||||||
.add_resource(ClearColor(Color::rgb(0.2, 0.2, 0.8)))
|
.add_resource(ClearColor(Color::rgb(0.2, 0.2, 0.8)))
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
|
.add_system(system1.system())
|
||||||
.run();
|
.run();
|
||||||
println!("Running another App.");
|
println!("Running another App.");
|
||||||
App::build()
|
App::build()
|
||||||
|
@ -15,7 +16,18 @@ fn main() {
|
||||||
return_from_run: true,
|
return_from_run: true,
|
||||||
})
|
})
|
||||||
.add_resource(ClearColor(Color::rgb(0.2, 0.8, 0.2)))
|
.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();
|
.run();
|
||||||
println!("Done.");
|
println!("Done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn system1() {
|
||||||
|
info!("logging from first app");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn system2() {
|
||||||
|
info!("logging from second app");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue