From 7d179b45f7e441af018d08c6f36f43f48af50b6e Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 26 Jan 2022 14:56:52 -0600 Subject: [PATCH] Fix a crash. --- src/pathfinding.rs | 47 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/pathfinding.rs b/src/pathfinding.rs index dbab0f5..4079e66 100644 --- a/src/pathfinding.rs +++ b/src/pathfinding.rs @@ -220,29 +220,30 @@ fn calculate_path( .remove::(); continue; } - let map = map.single(); - let coordinates_clone = *coordinates; - let destination_clone = *destination; - let query_pipeline_clone = query_pipeline.clone(); - let map_clone = map.clone(); - let shape_clone = (*shape).clone(); - let collider_set: StaticColliderComponentsSet = (&collider_query, &obstructions).into(); - let task = pool.spawn(async move { - find_path_for_shape( - entity, - coordinates_clone, - destination_clone, - query_pipeline_clone, - map_clone, - collider_set, - shape_clone, - ) - }); - commands - .entity(entity) - .insert(Calculating(task)) - .remove::() - .remove::(); + if let Ok(map) = map.get_single() { + let coordinates_clone = *coordinates; + let destination_clone = *destination; + let query_pipeline_clone = query_pipeline.clone(); + let map_clone = map.clone(); + let shape_clone = (*shape).clone(); + let collider_set: StaticColliderComponentsSet = (&collider_query, &obstructions).into(); + let task = pool.spawn(async move { + find_path_for_shape( + entity, + coordinates_clone, + destination_clone, + query_pipeline_clone, + map_clone, + collider_set, + shape_clone, + ) + }); + commands + .entity(entity) + .insert(Calculating(task)) + .remove::() + .remove::(); + } } }