Merge branch '4ydx/overflow-fix' into 'master'

Fix int overflows causing crash when using /goto

See merge request veloren/veloren!3656
This commit is contained in:
Imbris 2022-10-13 13:58:03 +00:00
commit 0c05fe54d3
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