Examples shouldn't use bytemuck to cast out of a get_mapped_range() BufferView #6191
Labels
area: documentation
Documentation for crate items, public or private
good first issue
Good for newcomers
type: bug
Something isn't working
Description
Currently, the examples use
bytemuck::cast_slice()
to cast u8 slices returned in theBufferView
fromget_mapped_range()
to slices of larger types (u64s, u32s etc.), but this call panics if the underlying slice is not aligned to the larger type.wgpu/examples/src/timestamp_queries/mod.rs
Line 169 in 26398ea
wgpu/examples/src/repeated_compute/mod.rs
Line 123 in 26398ea
At present, wgpu makes no guarantees about the alignment of
get_mapped_range()
, and in certain situations does in fact return a slice that is not u64-aligned.Until wgpu can guarantee alignment here, it would be nice to remove this footgun from the examples, as currently code that works there can mysteriously break when put into a larger project.
Additional Information
I had previously been using
bytemuck::cast_slice()
without issue in 0.18.x but upon updating to 22.x the alignment shifted. It only seems to have happened on the Vulkan backend.The text was updated successfully, but these errors were encountered: