Fix int overflows causing crash when using /goto

This commit is contained in:
4ydx 2022-10-13 13:58:02 +00:00 committed by Imbris
parent b677051ef8
commit 4ae332b8d1
2 changed files with 5 additions and 2 deletions

View File

@ -1858,8 +1858,11 @@ impl Client {
// 1 for the chunks needed bordering other chunks for meshing
// 1 as a buffer so that if the player moves back in that direction the chunks
// don't need to be reloaded
// Take the minimum of the adjusted difference vs the view_distance + 1 to
// prevent magnitude_squared from overflowing
if (chunk_pos - key)
.map(|e: i32| (e.unsigned_abs()).saturating_sub(2))
.map(|e: i32| (e.unsigned_abs()).saturating_sub(2).min(view_distance + 1))
.magnitude_squared()
> view_distance.pow(2)
{

View File

@ -276,7 +276,7 @@ impl VoxelMinimap {
)
.unwrap_or(0)
};
if cpos.distance_squared(self.last_pos.xy()) >= 1
if self.last_pos.xy() != cpos
|| self.last_pos.z != pos.z as i32
|| self.last_ceiling != ceiling_offset
|| new_chunks