From e4ee87ee27f959cee55a21f988b10f4917bf6941 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Thu, 20 Jan 2022 18:06:20 -0600 Subject: [PATCH] Various crash fixes. --- src/pathfinding.rs | 11 +++++++++-- src/visibility.rs | 27 ++++++++++++++------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/pathfinding.rs b/src/pathfinding.rs index 4dbaf5c..dbab0f5 100644 --- a/src/pathfinding.rs +++ b/src/pathfinding.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use bevy::{ + ecs::entity::Entities, prelude::*, tasks::{prelude::*, Task}, }; @@ -258,9 +259,15 @@ fn poll_tasks(mut commands: Commands, mut query: Query<(Entity, &mut Calculating } } -fn remove_destination(mut commands: Commands, removed: RemovedComponents) { +fn remove_destination( + mut commands: Commands, + entities: &Entities, + removed: RemovedComponents, +) { for entity in removed.iter() { - commands.entity(entity).remove::(); + if entities.contains(entity) { + commands.entity(entity).remove::(); + } } } diff --git a/src/visibility.rs b/src/visibility.rs index 0d08232..276f3f6 100644 --- a/src/visibility.rs +++ b/src/visibility.rs @@ -314,19 +314,20 @@ fn remove_visible( continue; } visible_entities.remove(&removed); - let map = map.single(); - let mut cache = HashMap::new(); - viewshed.update( - &viewer_entity, - &mut visible_entities, - start, - &*query_pipeline, - &collider_query, - map, - &visible, - &mut cache, - &mut changed, - ); + if let Ok(map) = map.get_single() { + let mut cache = HashMap::new(); + viewshed.update( + &viewer_entity, + &mut visible_entities, + start, + &*query_pipeline, + &collider_query, + map, + &visible, + &mut cache, + &mut changed, + ); + } } } }