Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up configure_set(s) erroring #9577

Merged
merged 3 commits into from Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/bevy_app/src/app.rs
Expand Up @@ -393,6 +393,7 @@ impl App {
}

/// Configures a system set in the default schedule, adding the set if it does not exist.
#[track_caller]
pub fn configure_set(
&mut self,
schedule: impl ScheduleLabel,
Expand All @@ -410,6 +411,7 @@ impl App {
}

/// Configures a collection of system sets in the default schedule, adding any sets that do not exist.
#[track_caller]
pub fn configure_sets(
&mut self,
schedule: impl ScheduleLabel,
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_ecs/src/schedule/config.rs
Expand Up @@ -388,6 +388,7 @@ pub struct SystemSetConfig {
}

impl SystemSetConfig {
#[track_caller]
fn new(set: BoxedSystemSet) -> Self {
// system type sets are automatically populated
// to avoid unintentionally broad changes, they cannot be configured
Expand Down Expand Up @@ -444,6 +445,7 @@ pub trait IntoSystemSetConfig: Sized {
}

impl<S: SystemSet> IntoSystemSetConfig for S {
#[track_caller]
fn into_config(self) -> SystemSetConfig {
SystemSetConfig::new(Box::new(self))
}
Expand Down
25 changes: 19 additions & 6 deletions crates/bevy_ecs/src/schedule/schedule.rs
Expand Up @@ -181,12 +181,14 @@ impl Schedule {
}

/// Configures a system set in this schedule, adding it if it does not exist.
#[track_caller]
pub fn configure_set(&mut self, set: impl IntoSystemSetConfig) -> &mut Self {
self.graph.configure_set(set);
self
}

/// Configures a collection of system sets in this schedule, adding them if they does not exist.
#[track_caller]
pub fn configure_sets(&mut self, sets: impl IntoSystemSetConfigs) -> &mut Self {
self.graph.configure_sets(sets);
self
Expand Down Expand Up @@ -550,8 +552,8 @@ impl ScheduleGraph {
let Some(prev) = config_iter.next() else {
return AddSystemsInnerResult {
nodes: Vec::new(),
densely_chained: true
}
densely_chained: true,
};
};
let mut previous_result = self.add_systems_inner(prev, true);
densely_chained = previous_result.densely_chained;
Expand Down Expand Up @@ -660,6 +662,7 @@ impl ScheduleGraph {
Ok(id)
}

#[track_caller]
fn configure_sets(&mut self, sets: impl IntoSystemSetConfigs) {
let SystemSetConfigs { sets, chained } = sets.into_configs();
let mut set_iter = sets.into_iter();
Expand All @@ -673,15 +676,25 @@ impl ScheduleGraph {
}
} else {
for set in set_iter {
self.configure_set_inner(set).unwrap();
if let Err(e) = self.configure_set_inner(set) {
// using `unwrap_or_else(panic!)` led to the error being reported
// from this line instead of in the user code
hymm marked this conversation as resolved.
Show resolved Hide resolved
panic!("{e}");
};
}
}
}

#[track_caller]
fn configure_set(&mut self, set: impl IntoSystemSetConfig) {
self.configure_set_inner(set).unwrap();
if let Err(e) = self.configure_set_inner(set) {
// using `unwrap_or_else(panic!)` led to the error being reported
// from this line instead of in the user code
panic!("{e}");
};
}

#[track_caller]
fn configure_set_inner(
&mut self,
set: impl IntoSystemSetConfig,
Expand Down Expand Up @@ -1482,7 +1495,7 @@ impl ScheduleGraph {
#[non_exhaustive]
pub enum ScheduleBuildError {
/// A system set contains itself.
#[error("`{0:?}` contains itself.")]
#[error("System set `{0}` contains itself.")]
HierarchyLoop(String),
/// The hierarchy of system sets contains a cycle.
#[error("System set hierarchy contains cycle(s).")]
Expand All @@ -1493,7 +1506,7 @@ pub enum ScheduleBuildError {
#[error("System set hierarchy contains redundant edges.")]
HierarchyRedundancy,
/// A system (set) has been told to run before itself.
#[error("`{0:?}` depends on itself.")]
#[error("System set `{0}` depends on itself.")]
DependencyLoop(String),
/// The dependency graph contains a cycle.
#[error("System dependencies contain cycle(s).")]
Expand Down