Skip to content

Commit 0f153ff

Browse files
authored
Prevent last_trigger_id from overflowing (#17978)
# Objective This prevents overflowing the `last_trigger_id` property that leads to a panic in debug mode. ```bash panicked at C:\XXX\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_ecs-0.15.2\src\world\unsafe_world_cell.rs:630:18: attempt to add with overflow Encountered a panic when applying buffers for system `bevy_sprite::calculate_bounds_2d`! Encountered a panic in system `bevy_ecs::schedule::executor::apply_deferred`! ``` ## Solution As this value is only used for detecting a change, we can wrap when it reaches max value. ## Testing This can be verified by running `cargo run --example observers`
1 parent b43c8f8 commit 0f153ff

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crates/bevy_ecs/src/world/unsafe_world_cell.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,9 @@ impl<'w> UnsafeWorldCell<'w> {
671671
pub(crate) unsafe fn increment_trigger_id(self) {
672672
self.assert_allows_mutable_access();
673673
// SAFETY: Caller ensure there are no outstanding references
674-
unsafe { (*self.ptr).last_trigger_id += 1 }
674+
unsafe {
675+
(*self.ptr).last_trigger_id = (*self.ptr).last_trigger_id.wrapping_add(1);
676+
}
675677
}
676678
}
677679

0 commit comments

Comments
 (0)