 d8383fb535
			
		
	
	
		d8383fb535
		
			
		
	
	
	
	
		
			
			# Objective - Move `PanicHandlerPlugin` into `bevy_app` - Fixes #12603 . ## Solution - I moved the `bevy_panic_handler` into `bevy_app` - Copy pasted `bevy_panic_handler`'s lib.rs into a separate module in `bevy_app` as a `panic_handler.rs` module file and added the `PanicHandlerPlugin` in lib.rs of `bevy_app` - added the dependency into `cargo.toml` ## Review notes - I probably want some feedback if I imported App and Plugin correctly in `panic_handler.rs` line 10 and 11. - As of yet I have not deleted `bevy_panic_handler` crate, wanted to get a check if I added it correctly. - Once validated that my move was correct, I'll probably have to remove the panic handler find default plugins which I probably need some help to find. - And then remove bevy panic_handler and making sure ci passes. - This is my first issue for contributing to bevy so let me know if I am doing anything wrong. ## tools context - rust is 1.76 version - Windows 11 --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
		
			
				
	
	
		
			53 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| //! This module provides panic handlers for [Bevy](https://bevyengine.org)
 | |
| //! apps, and automatically configures platform specifics (i.e. WASM or Android).
 | |
| //!
 | |
| //! By default, the [`PanicHandlerPlugin`] from this crate is included in Bevy's `DefaultPlugins`.
 | |
| //!
 | |
| //! For more fine-tuned control over panic behavior, disable the [`PanicHandlerPlugin`] or
 | |
| //! `DefaultPlugins` during app initialization.
 | |
| 
 | |
| use crate::App;
 | |
| use crate::Plugin;
 | |
| 
 | |
| /// Adds sensible panic handlers to Apps. This plugin is part of the `DefaultPlugins`. Adding
 | |
| /// this plugin will setup a panic hook appropriate to your target platform:
 | |
| /// * On WASM, uses [`console_error_panic_hook`](https://crates.io/crates/console_error_panic_hook), logging
 | |
| /// to the browser console.
 | |
| /// * Other platforms are currently not setup.
 | |
| ///
 | |
| /// ```no_run
 | |
| /// # use bevy_app::{App, NoopPluginGroup as MinimalPlugins, PluginGroup, PanicHandlerPlugin};
 | |
| /// fn main() {
 | |
| ///     App::new()
 | |
| ///         .add_plugins(MinimalPlugins)
 | |
| ///         .add_plugins(PanicHandlerPlugin)
 | |
| ///         .run();
 | |
| /// }
 | |
| /// ```
 | |
| ///
 | |
| /// If you want to setup your own panic handler, you should disable this
 | |
| /// plugin from `DefaultPlugins`:
 | |
| /// ```no_run
 | |
| /// # use bevy_app::{App, NoopPluginGroup as DefaultPlugins, PluginGroup, PanicHandlerPlugin};
 | |
| /// fn main() {
 | |
| ///     App::new()
 | |
| ///         .add_plugins(DefaultPlugins.build().disable::<PanicHandlerPlugin>())
 | |
| ///         .run();
 | |
| /// }
 | |
| /// ```
 | |
| #[derive(Default)]
 | |
| pub struct PanicHandlerPlugin;
 | |
| 
 | |
| impl Plugin for PanicHandlerPlugin {
 | |
|     fn build(&self, _app: &mut App) {
 | |
|         #[cfg(target_arch = "wasm32")]
 | |
|         {
 | |
|             console_error_panic_hook::set_once();
 | |
|         }
 | |
|         #[cfg(not(target_arch = "wasm32"))]
 | |
|         {
 | |
|             // Use the default target panic hook - Do nothing.
 | |
|         }
 | |
|     }
 | |
| }
 |