atagen

monolith

public
Star0
Watch0

Commit acf5e9848529

tarball

atagen <boss@atagen.co>2026-10-19 07:56 UTC

4 files changed+8-6
render-vk: return an error when staging memory is not mapped

Staging::bytes_mut gave an empty slice for a failed mapping, so stage_rows panicked indexing it. bytes and bytes_mut now return Error::StagingUnmapped.
Modified file: crates/render-vk/src/error.rs+2 additions
@@ -21,6 +21,8 @@ pub enum Error {
2121 DmabufUnsupported,
2222 #[error("cannot import dmabuf with format {0:?}")]
2323 UnsupportedDmabuf(smithay::backend::allocator::Format),
24+ #[error("staging memory is not mapped for the host")]
25+ StagingUnmapped,
2426 #[error("cannot read the shm buffer")]
2527 ShmAccess,
2628 #[error("interrupted while waiting for a sync point")]
Modified file: crates/render-vk/src/renderer/mod.rs+1 additions−1 deletions
@@ -592,7 +592,7 @@ impl VulkanRenderer {
592592 );
593593 })?;
594594 }
595- let mut data = staging.bytes()[..w as usize * h as usize * BYTES_PER_PIXEL].to_vec();
595+ let mut data = staging.bytes()?[..w as usize * h as usize * BYTES_PER_PIXEL].to_vec();
596596 if swap {
597597 for px in data.as_chunks_mut::<BYTES_PER_PIXEL>().0 {
598598 px.swap(0, 2);
Modified file: crates/render-vk/src/renderer/shm.rs+1 additions−1 deletions
@@ -112,7 +112,7 @@ pub(super) fn stage_rows<'a>(
112112 vk::BufferUsageFlags::TRANSFER_SRC,
113113 MemoryLocation::CpuToGpu,
114114 )?;
115- let dst = staging.bytes_mut();
115+ let dst = staging.bytes_mut()?;
116116 for i in 0..h {
117117 dst[i * line..(i + 1) * line].copy_from_slice(row(region.loc.y as usize + i));
118118 }
Modified file: crates/render-vk/src/staging.rs+4 additions−4 deletions
@@ -149,18 +149,18 @@ impl Staging {
149149 })
150150 }
151151
152- pub fn bytes(&self) -> &[u8] {
152+ pub fn bytes(&self) -> Result<&[u8], Error> {
153153 self.allocation
154154 .as_ref()
155155 .and_then(|a| a.mapped_slice())
156- .unwrap_or(&[])
156+ .ok_or(Error::StagingUnmapped)
157157 }
158158
159- pub fn bytes_mut(&mut self) -> &mut [u8] {
159+ pub fn bytes_mut(&mut self) -> Result<&mut [u8], Error> {
160160 self.allocation
161161 .as_mut()
162162 .and_then(|a| a.mapped_slice_mut())
163- .unwrap_or(&mut [])
163+ .ok_or(Error::StagingUnmapped)
164164 }
165165 }