Skip to content

Commit d6e6814

Browse files
SpecificProtagonistmockersf
authored andcommitted
Fix SimpleExecutor crash (#12076)
# Objective Since #9822, `SimpleExecutor` panics when an automatic sync point is inserted: ```rust let mut sched = Schedule::default(); sched.set_executor_kind(ExecutorKind::Simple); sched.add_systems((|_: Commands| (), || ()).chain()); sched.run(&mut World::new()); ``` ``` System's param_state was not found. Did you forget to initialize this system before running it? note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Encountered a panic in system `bevy_ecs::schedule::executor::apply_deferred`! ``` ## Solution Don't try to run the `apply_deferred` system.
1 parent b1f0615 commit d6e6814

File tree

1 file changed

+20
-1
lines changed
  • crates/bevy_ecs/src/schedule/executor

1 file changed

+20
-1
lines changed

crates/bevy_ecs/src/schedule/executor/simple.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use fixedbitset::FixedBitSet;
44
use std::panic::AssertUnwindSafe;
55

66
use crate::{
7-
schedule::{BoxedCondition, ExecutorKind, SystemExecutor, SystemSchedule},
7+
schedule::{
8+
executor::is_apply_deferred, BoxedCondition, ExecutorKind, SystemExecutor, SystemSchedule,
9+
},
810
world::World,
911
};
1012

@@ -86,6 +88,10 @@ impl SystemExecutor for SimpleExecutor {
8688
}
8789

8890
let system = &mut schedule.systems[system_index];
91+
if is_apply_deferred(system) {
92+
continue;
93+
}
94+
8995
let res = std::panic::catch_unwind(AssertUnwindSafe(|| {
9096
system.run((), world);
9197
}));
@@ -125,3 +131,16 @@ fn evaluate_and_fold_conditions(conditions: &mut [BoxedCondition], world: &mut W
125131
.map(|condition| condition.run((), world))
126132
.fold(true, |acc, res| acc && res)
127133
}
134+
135+
#[cfg(test)]
136+
#[test]
137+
fn skip_automatic_sync_points() {
138+
// Schedules automatically insert appy_deferred systems, but these should
139+
// not be executed as they only serve as markers and are not initialized
140+
use crate::prelude::*;
141+
let mut sched = Schedule::default();
142+
sched.set_executor_kind(ExecutorKind::Simple);
143+
sched.add_systems((|_: Commands| (), || ()).chain());
144+
let mut world = World::new();
145+
sched.run(&mut world);
146+
}

0 commit comments

Comments
 (0)