Skip to content

don't overflow when relations are empty #18891

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 1 commit into from
Apr 21, 2025

Conversation

mockersf
Copy link
Member

Objective

Solution

  • Don't overflow when substracting, bound at 0

Testing

  • Reproducer from the issue now works

@mockersf mockersf added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events labels Apr 21, 2025
@mockersf mockersf added this to the 0.16 milestone Apr 21, 2025
@@ -213,15 +213,15 @@ impl OrderedRelationshipSourceCollection for Vec<Entity> {

fn place_most_recent(&mut self, index: usize) {
if let Some(entity) = self.pop() {
let index = index.min(self.len() - 1);
let index = index.min(self.len().saturating_sub(1));
self.insert(index, entity);
}
}

fn place(&mut self, entity: Entity, index: usize) {
if let Some(current) = <[Entity]>::iter(self).position(|e| *e == entity) {
// The len is at least 1, so the subtraction is safe.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment suggests the - 1 should always be safe, so does it indicate something else wrong?

Noting that I approve of the change to saturating_sub generally.

Copy link
Member

Choose a reason for hiding this comment

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

This line here IMO cannot fail, as the position call cannot return Some if there are no items to filter.
The bugfix is thus in the other line that was changed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok that makes sense. This line was just changed while he was here.

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.

Makes sense!

@janhohenheim janhohenheim added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Apr 21, 2025
@mockersf mockersf added this pull request to the merge queue Apr 21, 2025
Merged via the queue into bevyengine:main with commit 12f71a8 Apr 21, 2025
39 checks passed
mockersf added a commit that referenced this pull request Apr 21, 2025
# Objective

- Fixes #18890 

## Solution

- Don't overflow when substracting, bound at 0

## Testing

- Reproducer from the issue now works
splo pushed a commit to splo/bevy that referenced this pull request Apr 29, 2025
# Objective

- Fixes bevyengine#18890 

## Solution

- Don't overflow when substracting, bound at 0

## Testing

- Reproducer from the issue now works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior 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.

EntityWorldMut::insert_children panics on index 0
4 participants