From f16333d2585aa685026d203bbfec27cfb3112a2e Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 1 Sep 2021 11:34:38 -0500 Subject: [PATCH] Fix out-of-bounds error. --- src/visibility.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/visibility.rs b/src/visibility.rs index a53ce19..876e7c2 100644 --- a/src/visibility.rs +++ b/src/visibility.rs @@ -257,6 +257,9 @@ fn update_visible_and_revealed_tiles( } for v in viewshed.visible.iter() { let idx = v.to_index(map.width); + if idx >= revealed_tiles.len() || idx >= visible_tiles.len() { + continue; + } revealed_tiles[idx] = true; visible_tiles[idx] = true; } @@ -285,6 +288,9 @@ fn log_visible( let collider_set = QueryPipelineColliderComponentsSet(&collider_query); let shape = Cuboid::new(Vec2::new(0.49, 0.49).into()); for viewed_coordinates in &viewshed.visible { + if coordinates.distance(viewed_coordinates) >= viewshed.range as f32 - 1.5 { + continue; + } let shape_pos = ( Vec2::new(viewed_coordinates.x() + 0.5, viewed_coordinates.y() + 0.5), 0.0,