mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
add more logs when despawning entities (#3851)
# Objective - Provide more information when despawning an entity ## Solution - Add a debug log when despawning an entity - Add spans to the recursive ways of despawning an entity ```sh RUST_LOG=debug cargo run --example panic --features trace # RUST_LOG=debug needed to show debug logs from bevy_ecs # --features trace needed to have the extra spans ... DEBUG bevy_app:frame:stage{name=Update}:system_commands{name="panic::despawn_parent"}:command{name="DespawnRecursive" entity=0v0}: bevy_ecs::world: Despawning entity 1v0 DEBUG bevy_app:frame:stage{name=Update}:system_commands{name="panic::despawn_parent"}:command{name="DespawnRecursive" entity=0v0}: bevy_ecs::world: Despawning entity 0v0 ```
This commit is contained in:
parent
16133de8cd
commit
8630b194dc
4 changed files with 47 additions and 4 deletions
|
@ -17,13 +17,13 @@ use crate::{
|
|||
storage::{Column, SparseSet, Storages},
|
||||
system::Resource,
|
||||
};
|
||||
use bevy_utils::tracing::debug;
|
||||
use std::{
|
||||
any::TypeId,
|
||||
fmt,
|
||||
mem::ManuallyDrop,
|
||||
sync::atomic::{AtomicU32, Ordering},
|
||||
};
|
||||
|
||||
mod identifier;
|
||||
|
||||
pub use identifier::WorldId;
|
||||
|
@ -463,6 +463,7 @@ impl World {
|
|||
/// ```
|
||||
#[inline]
|
||||
pub fn despawn(&mut self, entity: Entity) -> bool {
|
||||
debug!("Despawning entity {:?}", entity);
|
||||
self.get_entity_mut(entity)
|
||||
.map(|e| {
|
||||
e.despawn();
|
||||
|
|
|
@ -9,13 +9,15 @@ use bevy_utils::tracing::debug;
|
|||
/// Despawns the given entity and all its children recursively
|
||||
#[derive(Debug)]
|
||||
pub struct DespawnRecursive {
|
||||
entity: Entity,
|
||||
/// Target entity
|
||||
pub entity: Entity,
|
||||
}
|
||||
|
||||
/// Despawns the given entity's children recursively
|
||||
#[derive(Debug)]
|
||||
pub struct DespawnChildrenRecursive {
|
||||
entity: Entity,
|
||||
/// Target entity
|
||||
pub entity: Entity,
|
||||
}
|
||||
|
||||
/// Function for despawning an entity and all its children
|
||||
|
@ -54,12 +56,26 @@ fn despawn_children(world: &mut World, entity: Entity) {
|
|||
|
||||
impl Command for DespawnRecursive {
|
||||
fn write(self, world: &mut World) {
|
||||
#[cfg(feature = "trace")]
|
||||
let _span = bevy_utils::tracing::info_span!(
|
||||
"command",
|
||||
name = "DespawnRecursive",
|
||||
entity = bevy_utils::tracing::field::debug(self.entity)
|
||||
)
|
||||
.entered();
|
||||
despawn_with_children_recursive(world, self.entity);
|
||||
}
|
||||
}
|
||||
|
||||
impl Command for DespawnChildrenRecursive {
|
||||
fn write(self, world: &mut World) {
|
||||
#[cfg(feature = "trace")]
|
||||
let _span = bevy_utils::tracing::info_span!(
|
||||
"command",
|
||||
name = "DespawnChildrenRecursive",
|
||||
entity = bevy_utils::tracing::field::debug(self.entity)
|
||||
)
|
||||
.entered();
|
||||
despawn_children(world, self.entity);
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +106,14 @@ impl<'w> DespawnRecursiveExt for EntityMut<'w> {
|
|||
/// Despawns the provided entity and its children.
|
||||
fn despawn_recursive(mut self) {
|
||||
let entity = self.id();
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
let _span = bevy_utils::tracing::info_span!(
|
||||
"despawn_recursive",
|
||||
entity = bevy_utils::tracing::field::debug(entity)
|
||||
)
|
||||
.entered();
|
||||
|
||||
// SAFE: EntityMut is consumed so even though the location is no longer
|
||||
// valid, it cannot be accessed again with the invalid location.
|
||||
unsafe {
|
||||
|
@ -99,6 +123,14 @@ impl<'w> DespawnRecursiveExt for EntityMut<'w> {
|
|||
|
||||
fn despawn_descendants(&mut self) {
|
||||
let entity = self.id();
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
let _span = bevy_utils::tracing::info_span!(
|
||||
"despawn_descendants",
|
||||
entity = bevy_utils::tracing::field::debug(entity)
|
||||
)
|
||||
.entered();
|
||||
|
||||
// SAFE: The location is updated.
|
||||
unsafe {
|
||||
despawn_children(self.world_mut(), entity);
|
||||
|
|
|
@ -10,7 +10,14 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"]
|
|||
categories = ["game-engines", "graphics", "gui", "rendering"]
|
||||
|
||||
[features]
|
||||
trace = [ "bevy_app/trace", "bevy_ecs/trace", "bevy_log/trace", "bevy_render/trace", "bevy_core_pipeline/trace" ]
|
||||
trace = [
|
||||
"bevy_app/trace",
|
||||
"bevy_core_pipeline/trace",
|
||||
"bevy_ecs/trace",
|
||||
"bevy_log/trace",
|
||||
"bevy_render/trace",
|
||||
"bevy_transform/trace"
|
||||
]
|
||||
trace_chrome = [ "bevy_log/tracing-chrome" ]
|
||||
trace_tracy = ["bevy_render/tracing-tracy", "bevy_log/tracing-tracy" ]
|
||||
wgpu_trace = ["bevy_render/wgpu_trace"]
|
||||
|
|
|
@ -8,6 +8,9 @@ repository = "https://github.com/bevyengine/bevy"
|
|||
license = "MIT OR Apache-2.0"
|
||||
keywords = ["bevy"]
|
||||
|
||||
[features]
|
||||
trace = []
|
||||
|
||||
[dependencies]
|
||||
# bevy
|
||||
bevy_app = { path = "../bevy_app", version = "0.7.0-dev" }
|
||||
|
|
Loading…
Reference in a new issue