Various crash fixes.

This commit is contained in:
Nolan Darilek 2022-01-20 18:06:20 -06:00
parent 488037d074
commit e4ee87ee27
2 changed files with 23 additions and 15 deletions

View File

@ -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<Destination>) {
fn remove_destination(
mut commands: Commands,
entities: &Entities,
removed: RemovedComponents<Destination>,
) {
for entity in removed.iter() {
commands.entity(entity).remove::<Calculating>();
if entities.contains(entity) {
commands.entity(entity).remove::<Calculating>();
}
}
}

View File

@ -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,
);
}
}
}
}