Skip to content

Remove all existing system order ambiguities in DefaultPlugins #15031

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

Merged
merged 15 commits into from
Sep 3, 2024

Conversation

alice-i-cecile
Copy link
Member

@alice-i-cecile alice-i-cecile commented Sep 3, 2024

Objective

As discussed in #7386, system order ambiguities within DefaultPlugins are a source of bugs in the engine and badly pollute diagnostic output for users.

We should eliminate them!

This PR is an alternative to #15027: with all external ambiguities silenced, this should be much less prone to merge conflicts and the test output should be much easier for authors to understand.

Note that system order ambiguities are still permitted in the RenderApp: these need a bit of thought in terms of how to test them, and will be fairly involved to fix. While these aren't good, they'll generally only cause graphical bugs, not logic ones.

Solution

All remaining system order ambiguities have been resolved.
Review this PR commit-by-commit to see how each of these problems were fixed.

Testing

cargo run --example ambiguity_detection passes with no panics or logging!

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change A-Cross-Cutting Impacts the entire engine S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 3, 2024
Comment on lines +93 to +97
app.ignore_ambiguity(
bevy_app::PostUpdate,
bevy_animation::animate_targets,
bevy_ui::ui_layout_system,
);
Copy link
Member

@Vrixyz Vrixyz Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the previous context comments, that said I can understand they are difficult to balance for maintainability and correctness.

does that refer to all external ambiguities silenced ?

Copy link
Member Author

@alice-i-cecile alice-i-cecile Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was justified using the comments just a few lines up (line 85), which state that UI cannot be animated :) I'd like to change that eventually of course!

Copy link
Member

@janhohenheim janhohenheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice that you were able to get this to zero! I looked over it and all of this makes sense. Only thing I dislike about this is that allowing ambiguities between concrete systems seems somewhat brittle and inelegant, like using systems for ordering. Would it be feasible to change the ambiguity ignores to system sets? I'm also fine with leaving this for a follow up.
Re CI failure: the CTRL-C handler should probably be last

@@ -226,7 +228,8 @@ fn build_text_interop(app: &mut App) {
.in_set(UiSystem::PostLayout)
.after(bevy_text::remove_dropped_font_atlas_sets)
// Text2d and bevy_ui text are entirely on separate entities
.ambiguous_with(bevy_text::update_text2d_layout),
.ambiguous_with(bevy_text::update_text2d_layout)
.ambiguous_with(bevy_text::calculate_bounds_text2d),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these two should be in a single set to ignore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly: I wanted to keep the changes relatively minimal though.

Comment on lines +504 to 507
/// System order ambiguities between systems in this set are ignored:
/// each [`build_directional_light_cascades`] system is independent of the others,
/// and should operate on distinct sets of entities.
UpdateDirectionalLightCascades,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(out of scope for this PR)

is this an opportunity to add a macro to mark that ambiguity is allowed there ? (for better type safety, avoid outdated comments)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, possibly. "Ignore all ambiguities with self in set" isn't a common pattern, but it's not a rare one.

Copy link
Member

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a good middle ground -- declare bankruptcy on existing ambiguities but enforce no net new ones going forward. we can always go back and develop better fixes for these later.

@alice-i-cecile
Copy link
Member Author

this seems like a good middle ground -- declare bankruptcy on existing ambiguities but enforce no net new ones going forward. we can always go back and develop better fixes for these later.

I'm actually pretty happy with most of these fixes! The rendering sets are a bit weird and implicit, but I think ultimately correct. I'd like to make text and text2d play nicer with each other / be less distinct, but that's another big project. Same with making UI animatable.

My main complaint is around handle_internal_asset_events: dropping an exclusive system in the middle of PreUpdate feels very messy to me and will definitely impact parallelism in an unpredictable way.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 3, 2024
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 3, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 3, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 3, 2024
Merged via the queue into bevyengine:main with commit 4ac2a63 Sep 3, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Cross-Cutting Impacts the entire engine C-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants