From c3a5144ae04b8f0d4c6ecfb93f78c75fc34ae7f4 Mon Sep 17 00:00:00 2001 From: qthree Date: Tue, 20 Oct 2020 13:24:33 +0700 Subject: [PATCH] Fix regression in device_create_swap_chain It was caused by new behavior of Storage::remove. --- wgpu-core/src/hub.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index dbbe5959a..4252141e9 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -183,13 +183,19 @@ impl Storage { } } - //Prevents panic on out of range access. + // Prevents panic on out of range access, allows Vacant elements. pub(crate) fn try_remove(&mut self, id: I) -> Option { - let (index, epoch, backend) = id.unzip(); + let (index, epoch, _) = id.unzip(); if index as usize >= self.map.len() { - return None; + None + } else if let Element::Occupied(value, storage_epoch) = + std::mem::replace(&mut self.map[index as usize], Element::Vacant) + { + assert_eq!(epoch, storage_epoch); + Some(value) + } else { + None } - self.remove(I::zip(index, epoch, backend)) } pub(crate) fn iter(&self, backend: Backend) -> impl Iterator {