bevy/crates/bevy_app/src
Chris Juchem 49661b99fe
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 18:06:05 +00:00
..
app.rs Remove extra call to clear_trackers (#13762) 2024-06-10 18:06:05 +00:00
lib.rs Computed State & Sub States (#11426) 2024-05-02 19:36:23 +00:00
main_schedule.rs fix docs around StateTransition and remove references to `apply_sta… (#13772) 2024-06-10 13:23:14 +00:00
panic_handler.rs Move PanicHandlerPlugin into bevy_app (#12640) 2024-03-29 02:04:56 +00:00
plugin_group.rs Added add_group to PluginGroupBuilder (#9530) 2024-02-25 21:23:28 +00:00
plugin.rs Add on_unimplemented Diagnostics to Most Public Traits (#13347) (#13662) 2024-06-04 00:31:34 +00:00
schedule_runner.rs Simplify runner app exit code. (#13074) 2024-04-23 20:42:00 +00:00
sub_app.rs Remove extra call to clear_trackers (#13762) 2024-06-10 18:06:05 +00:00