Skip to content

Commit

Permalink
queue_write_texture: Validate the destination texture.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblandy committed Jan 14, 2023
1 parent 4400ff8 commit 70ea09f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}

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)?;
Expand Down Expand Up @@ -707,6 +709,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
}

// 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
Expand Down

0 comments on commit 70ea09f

Please sign in to comment.