Fix out-of-bounds error.

This commit is contained in:
Nolan Darilek 2021-09-01 11:34:38 -05:00
parent 9a85544ad5
commit f16333d258

View File

@ -257,6 +257,9 @@ fn update_visible_and_revealed_tiles(
} }
for v in viewshed.visible.iter() { for v in viewshed.visible.iter() {
let idx = v.to_index(map.width); let idx = v.to_index(map.width);
if idx >= revealed_tiles.len() || idx >= visible_tiles.len() {
continue;
}
revealed_tiles[idx] = true; revealed_tiles[idx] = true;
visible_tiles[idx] = true; visible_tiles[idx] = true;
} }
@ -285,6 +288,9 @@ fn log_visible(
let collider_set = QueryPipelineColliderComponentsSet(&collider_query); let collider_set = QueryPipelineColliderComponentsSet(&collider_query);
let shape = Cuboid::new(Vec2::new(0.49, 0.49).into()); let shape = Cuboid::new(Vec2::new(0.49, 0.49).into());
for viewed_coordinates in &viewshed.visible { for viewed_coordinates in &viewshed.visible {
if coordinates.distance(viewed_coordinates) >= viewshed.range as f32 - 1.5 {
continue;
}
let shape_pos = ( let shape_pos = (
Vec2::new(viewed_coordinates.x() + 0.5, viewed_coordinates.y() + 0.5), Vec2::new(viewed_coordinates.x() + 0.5, viewed_coordinates.y() + 0.5),
0.0, 0.0,