From 4a1e9c2e4d313999a082fc80c26e2b8bae9a832d Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Thu, 24 Nov 2022 15:39:16 +0100 Subject: [PATCH] Fix incorrect offset in get_mapped_range. --- wgpu-core/src/device/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 494fa41b7a9..fc5d4afde52 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -5688,7 +5688,10 @@ impl Global { max: range.end, }); } - unsafe { Ok((ptr.as_ptr().offset(offset as isize), range_size)) } + // ptr points to the beginning of the range we mapped in map_async + // rather thant the beginning of the buffer. + let relative_offset = (offset - range.start) as isize; + unsafe { Ok((ptr.as_ptr().offset(relative_offset), range_size)) } } resource::BufferMapState::Idle | resource::BufferMapState::Waiting(_) => { Err(BufferAccessError::NotMapped)