From da3b62d7d61b39c466d37f663557a3c624fcd95f 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 b542d711c9..86c79a9a6d 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -5677,7 +5677,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)