gfx-rs/wgpu · error
buffer slice can not be empty
Error message
buffer slice can not be empty
What it means
Panic from BufferSlice's size_expect_nonzero (reached via set_index_buffer): the slice size is 0, which is not a valid index buffer binding. The faulty input is an empty (zero-size) buffer slice passed to set_index_buffer.
Source
Thrown at wgpu/src/api/buffer.rs:681
/// You should usually not need to call this, and if you received the buffer from code you
/// do not control, you should refrain from accessing the buffer outside the bounds of the
/// slice. Nevertheless, it’s possible to get this access, so this method makes it simple.
pub fn buffer(&self) -> &'a Buffer {
self.buffer
}
/// Returns the offset in [`Self::buffer()`] this slice starts at.
pub fn offset(&self) -> BufferAddress {
self.offset
}
/// Returns the size of this slice.
pub fn size(&self) -> BufferAddress {
self.size
}
pub(crate) fn size_expect_nonzero(&self) -> BufferSize {
BufferSize::new(self.size).expect("buffer slice can not be empty")
}
}
impl<'a> TryFrom<BufferSlice<'a>> for crate::BufferBinding<'a> {
type Error = ();
/// Convert a [`BufferSlice`] to an equivalent [`BufferBinding`],
/// provided that it will be used without a dynamic offset.
fn try_from(value: BufferSlice<'a>) -> Result<Self, Self::Error> {
Ok(BufferBinding {
buffer: value.buffer,
offset: value.offset,
size: Some(NonZero::new(value.size()).ok_or(())?),
})
}
}
impl<'a> TryFrom<BufferSlice<'a>> for crate::BindingResource<'a> {View on GitHub (pinned to 3e11ff59bf)
Solutions
- Bind a non-empty slice covering actual index data
- Check buffer.size() > 0 before constructing/binding the slice
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at wgpu/src/api/buffer.rs:681 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of gfx-rs/wgpu@3e11ff59bf (2026-09-03).
Data as JSON: /api/errors/bf0fe5594945ff05.
Report an issue: GitHub.