bevy/crates/bevy_ecs/src
Chris Juchem 65dbfe249b
Remove extra call to clear_trackers (#13762)
Fixes #13758.

# Objective

Calling `update` on the main app already calls `clear_trackers`. Calling
it again in `SubApps::update` caused RemovedCompenet Events to be
cleared earlier than they should be.

## Solution

- Don't call clear_trackers an extra time.

## Testing

I manually tested the fix with this unit test: 
```
#[cfg(test)]
mod test {
    use crate::core::{FrameCount, FrameCountPlugin};
    use crate::prelude::*;

    #[test]
    fn test_next_frame_removal() {
        #[derive(Component)]
        struct Foo;

        #[derive(Resource)]
        struct RemovedCount(usize);

        let mut app = App::new();
        app.add_plugins(FrameCountPlugin);
        app.add_systems(Startup, |mut commands: Commands| {
            for _ in 0..100 {
                commands.spawn(Foo);
            }
            commands.insert_resource(RemovedCount(0));
        });

        app.add_systems(First, |counter: Res<FrameCount>| {
            println!("Frame {}:", counter.0)
        });

        fn detector_system(
            mut removals: RemovedComponents<Foo>,
            foos: Query<Entity, With<Foo>>,
            mut removed_c: ResMut<RemovedCount>,
        ) {
            for e in removals.read() {
                println!("  Detected removed Foo component for {e:?}");
                removed_c.0 += 1;
            }
            let c = foos.iter().count();
            println!("  Total Foos: {}", c);
            assert_eq!(c + removed_c.0, 100);
        }
        fn deleter_system(foos: Query<Entity, With<Foo>>, mut commands: Commands) {
            foos.iter().next().map(|e| {
                commands.entity(e).remove::<Foo>();
            });
        }
        app.add_systems(Update, (detector_system, deleter_system).chain());

        app.update();
        app.update();
        app.update();
        app.update();
    }
}
```
2024-06-10 20:23:06 +02:00
..
entity Update serialize flag for bevy_ecs (#13740) 2024-06-10 19:31:41 +02:00
identifier feat: Reflection implementations on Identifier (#13648) 2024-06-03 16:33:14 +00:00
query Add on_unimplemented Diagnostics to Most Public Traits (#13347) (#13662) 2024-06-04 00:31:34 +00:00
reflect Map entities from a resource when written to the world. (#13650) 2024-06-03 16:33:24 +00:00
schedule Add on_unimplemented Diagnostics to Most Public Traits (#13347) (#13662) 2024-06-04 00:31:34 +00:00
storage Fix uses of "it's" vs "its". (#13033) 2024-04-19 18:17:31 +00:00
system Fix EntityCommands::despawn docs (#13774) 2024-06-09 20:52:52 +02:00
world Remove extra call to clear_trackers (#13762) 2024-06-10 20:23:06 +02:00
archetype.rs Adding some docs for archetype internals (#12578) 2024-03-23 01:48:31 +00:00
batching.rs Parallel event reader (#12554) 2024-04-22 16:37:42 +00:00
bundle.rs Add on_unimplemented Diagnostics to Most Public Traits (#13347) (#13662) 2024-06-04 00:31:34 +00:00
change_detection.rs Implement WorldQuery and QueryData on Mut. (#13338) 2024-05-14 12:38:31 +00:00
component.rs Add on_unimplemented Diagnostics to Most Public Traits (#13347) (#13662) 2024-06-04 00:31:34 +00:00
event.rs Fix a few typos (#13404) 2024-06-04 00:51:03 +00:00
intern.rs Moves intern and label modules into bevy_ecs (#12772) 2024-04-08 15:34:11 +00:00
label.rs Use ptr::from_ref and ptr::addr_eq in macro (#13081) 2024-04-24 01:54:24 +00:00
lib.rs Implement a SystemBuilder for building SystemParams (#13123) 2024-05-22 00:58:37 +00:00
removal_detection.rs Remove extra call to clear_trackers (#13762) 2024-06-10 20:23:06 +02:00