From 70ea09f39c084b707a2c62ea0ddbb17722619aeb Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Fri, 13 Jan 2023 13:03:56 -0800 Subject: [PATCH] queue_write_texture: Validate the destination texture. --- wgpu-core/src/device/queue.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index ba0fb053da..2f4b2bcfb4 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -595,7 +595,9 @@ impl Global { } let (mut texture_guard, _) = hub.textures.write(&mut token); // For clear we need write access to the texture. TODO: Can we acquire write lock later? - let dst = texture_guard.get_mut(destination.texture).unwrap(); + let dst = texture_guard + .get_mut(destination.texture) + .map_err(|_| TransferError::InvalidTexture(destination.texture))?; let (selector, dst_base, texture_format) = extract_texture_selector(destination, size, dst)?; @@ -707,6 +709,10 @@ impl Global { } } + // Re-get `dst` immutably here, so that the mutable borrow of the + // `texture_guard.get_mut` above ends in time for the `clear_texture` + // call above. Since we've held `texture_guard` the whole time, we know + // the texture hasn't gone away in the mean time, so we can unwrap. let dst = texture_guard.get(destination.texture).unwrap(); let transition = trackers .textures