Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Fix crash on integer overflow in debug mode (#973)
Browse files Browse the repository at this point in the history
* Fix crash on integer overflow in debug mode

* Use saturating_add_signed function
  • Loading branch information
0HyperCube authored Jun 21, 2023
1 parent e6bb9fd commit 99aea67
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions emergence_lib/src/geometry/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,13 @@ impl VoxelPos {
let mut reachable_neighbors = [Self::ZERO; 21];

for layer in 0..=2 {
let height_offset = DiscreteHeight(layer as u8 - 1);
let height_offset = layer as i8 - 1;
for (i, &hex) in hexagon.iter().enumerate() {
let index = layer * 7 + i;

reachable_neighbors[index] = VoxelPos {
hex,
height: self.height + height_offset,
height: DiscreteHeight(self.height.0.saturating_add_signed(height_offset)),
};
}
}
Expand Down

0 comments on commit 99aea67

Please sign in to comment.