mirror of
https://github.com/bevyengine/bevy
synced 2024-12-24 12:03:14 +00:00
efda7f3f9c
Takes the first two commits from #15375 and adds suggestions from this comment: https://github.com/bevyengine/bevy/pull/15375#issuecomment-2366968300 See #15375 for more reasoning/motivation. ## Rebasing (rerunning) ```rust git switch simpler-lint-fixes git reset --hard main cargo fmt --all -- --unstable-features --config normalize_comments=true,imports_granularity=Crate cargo fmt --all git add --update git commit --message "rustfmt" cargo clippy --workspace --all-targets --all-features --fix cargo fmt --all -- --unstable-features --config normalize_comments=true,imports_granularity=Crate cargo fmt --all git add --update git commit --message "clippy" git cherry-pick e6c0b94f6795222310fb812fa5c4512661fc7887 ```
51 lines
1.8 KiB
Rust
51 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, 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.
|
|
}
|
|
}
|
|
}
|