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
					
				| @ -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"); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
| @ -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"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -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 | ||||
|                         ), | ||||
|                     } | ||||
|                 } | ||||
|                 _ => {} | ||||
|             }, | ||||
|  | ||||
| @ -8,6 +8,7 @@ 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() | ||||
| @ -15,7 +16,18 @@ fn main() { | ||||
|             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"); | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 François
						François