diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index d2c15ec73..63a3b61e9 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -93,7 +93,16 @@ impl RawPass { self.data as usize - self.base as usize } - pub unsafe fn into_vec(self) -> (Vec, id::CommandEncoderId) { + /// Recover the data vector of the pass, consuming `self`. + unsafe fn into_vec(mut self) -> (Vec, id::CommandEncoderId) { + (self.invalidate(), self.parent) + } + + /// Make pass contents invalid, return the contained data. + /// + /// Any following access to the pass will result in a crash + /// for accessing address 0. + pub unsafe fn invalidate(&mut self) -> Vec { let size = self.size(); assert!( size <= self.capacity, @@ -102,7 +111,10 @@ impl RawPass { self.capacity ); let vec = Vec::from_raw_parts(self.base, size, self.capacity); - (vec, self.parent) + self.data = ptr::null_mut(); + self.base = ptr::null_mut(); + self.capacity = 0; + vec } unsafe fn ensure_extra_size(&mut self, extra_size: usize) { diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 0cc592030..34815f2d1 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -160,8 +160,7 @@ impl super::RawPass { pub unsafe fn finish_render(mut self) -> (Vec, id::CommandEncoderId) { self.finish(RenderCommand::End); - let (vec, parent_id) = self.into_vec(); - (vec, parent_id) + self.into_vec() } }