{"record":{"id":"bf0fe5594945ff05","repo":"gfx-rs/wgpu","slug":"buffer-slice-can-not-be-empty","errorCode":null,"errorMessage":"buffer slice can not be empty","messagePattern":"buffer slice can not be empty","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"wgpu/src/api/buffer.rs","lineNumber":681,"sourceCode":"    /// You should usually not need to call this, and if you received the buffer from code you\n    /// do not control, you should refrain from accessing the buffer outside the bounds of the\n    /// slice. Nevertheless, it’s possible to get this access, so this method makes it simple.\n    pub fn buffer(&self) -> &'a Buffer {\n        self.buffer\n    }\n\n    /// Returns the offset in [`Self::buffer()`] this slice starts at.\n    pub fn offset(&self) -> BufferAddress {\n        self.offset\n    }\n\n    /// Returns the size of this slice.\n    pub fn size(&self) -> BufferAddress {\n        self.size\n    }\n\n    pub(crate) fn size_expect_nonzero(&self) -> BufferSize {\n        BufferSize::new(self.size).expect(\"buffer slice can not be empty\")\n    }\n}\n\nimpl<'a> TryFrom<BufferSlice<'a>> for crate::BufferBinding<'a> {\n    type Error = ();\n\n    /// Convert a [`BufferSlice`] to an equivalent [`BufferBinding`],\n    /// provided that it will be used without a dynamic offset.\n    fn try_from(value: BufferSlice<'a>) -> Result<Self, Self::Error> {\n        Ok(BufferBinding {\n            buffer: value.buffer,\n            offset: value.offset,\n            size: Some(NonZero::new(value.size()).ok_or(())?),\n        })\n    }\n}\n\nimpl<'a> TryFrom<BufferSlice<'a>> for crate::BindingResource<'a> {","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/wgpu/src/api/buffer.rs#L663-L699","documentation":"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.","triggerScenarios":"Thrown at wgpu/src/api/buffer.rs:681 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Bind a non-empty slice covering actual index data","Check buffer.size() > 0 before constructing/binding the slice"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3e11ff59bf3f9795d285ecc045014089640d7248","analyzedAt":"2026-09-03T01:43:21.459Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}