Skip to content

despawn_recursive causing Tracy error #15299

Open

Description

Bevy version

0.14.2

What you did

I have a project that involves spawning and despawning many entities. I am having trouble running Tracy with the project because of a Tracy error caused by despawn_recursive.

What went wrong

Tracy errors out because it runs over the limit of systems that can be tracked (32,000).

Additional information

The reason there are over 32,000 systems running is that DespawnRecursive uses the entity that was despawned to create the trace name, creating a unique system to be tracked in Tracy. This can be seen in the Statistics window in Tracy.

I was able to workaround the problem by limiting despawn_recursives, but this only delays the problem, as my project still eventually hits the 32k limit. Changing despawn_recursive to despawn, fixes the issue, but I need despawn_recursive in some places.

Tracy Error

tracy_error

Tracy Statistics, filled with 32,000 unique DespawnRecursive commands

tracy_statistics

Code causing the problem in bevy_hierarchy/src/hierarchy.rs

https://github.com/bevyengine/bevy/blob/1bb8007dceb03f41b20317bb44fcdfec1d70513c/crates/bevy_hierarchy/src/hierarchy.rs#L57C1-L81C2

impl Command for DespawnRecursive {
    fn apply(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 apply(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_recursive(world, self.entity);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-DiagnosticsLogging, crash handling, error reporting and performance analysisA-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions