From d719e117ada91e9cf2c3eeedad2cf77c0ad6ba92 Mon Sep 17 00:00:00 2001 From: Thinkofname Date: Thu, 21 Apr 2016 13:38:49 +0100 Subject: [PATCH] Work around a block mapping bug --- src/world/storage.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/world/storage.rs b/src/world/storage.rs index 307f8d4..baaff00 100644 --- a/src/world/storage.rs +++ b/src/world/storage.rs @@ -40,13 +40,16 @@ impl BlockStorage { if old == b { return false; } - // Clean up old block + // Clean up the old block { - let idx = self.rev_block_map[&old]; - let info = &mut self.block_map[idx]; - info.1 -= 1; - if info.1 == 0 { // None left of this type - self.rev_block_map.remove(&old); + // BUG: This lookup should never fail but sometimes will + // due to an issue with loading chunks from the server. + if let Some(idx) = self.rev_block_map.get(&old).cloned() { + let info = &mut self.block_map[idx]; + info.1 -= 1; + if info.1 == 0 { // None left of this type + self.rev_block_map.remove(&old); + } } }