Don't panic if a region can't be found for a deleted entity

This commit is contained in:
Imbris 2020-01-02 23:23:38 -05:00
parent 38c48317f7
commit 63d74eb8ba

View File

@ -32,7 +32,7 @@ use common::{
terrain::{block::Block, TerrainChunkSize, TerrainGrid}, terrain::{block::Block, TerrainChunkSize, TerrainGrid},
vol::{ReadVol, RectVolSize, Vox}, vol::{ReadVol, RectVolSize, Vox},
}; };
use log::{debug, error}; use log::{debug, error, warn};
use metrics::ServerMetrics; use metrics::ServerMetrics;
use rand::Rng; use rand::Rng;
use specs::{ use specs::{
@ -1221,14 +1221,20 @@ impl StateExt for State {
let res = self.ecs_mut().delete_entity(entity); let res = self.ecs_mut().delete_entity(entity);
if res.is_ok() { if res.is_ok() {
if let (Some(uid), Some(pos)) = (maybe_uid, maybe_pos) { if let (Some(uid), Some(pos)) = (maybe_uid, maybe_pos) {
let region_key = self if let Some(region_key) = self
.ecs() .ecs()
.read_resource::<common::region::RegionMap>() .read_resource::<common::region::RegionMap>()
.find_region(entity, pos.0) .find_region(entity, pos.0)
.expect("Failed to find region containing entity during entity deletion"); {
self.ecs() self.ecs()
.write_resource::<DeletedEntities>() .write_resource::<DeletedEntities>()
.record_deleted_entity(uid, region_key); .record_deleted_entity(uid, region_key);
} else {
// Don't panic if the entity wasn't found in a region maybe it was just created
// and then deleted before the region manager had a chance to assign it a
// region
warn!("Failed to find region containing entity during entity deletion, assuming it wasn't sent to any clients and so deletion doesn't need to be recorded for sync purposes");
}
} }
} }
res res