bevyengine/bevy · critical
You can't use `get_binding` with a `ShaderBuffer`; fetch the
Error message
You can't use `get_binding` with a `ShaderBuffer`; fetch the buffer from the `RenderAssets<GpuShaderBuffer>` instead
What it means
OwnedBindingResource::get_binding() (bind_group.rs:825) panics on the ShaderBuffer variant because a ShaderBuffer only holds CPU-side data plus identity - its GPU buffer exists only after preparation, inside the RenderAssets<GpuShaderBuffer> collection. The message tells you to fetch the real buffer from that resource instead of trying to convert the ShaderBuffer directly into a BindingResource.
Source
Thrown at crates/bevy_render/src/render_resource/bind_group.rs:825
/// Data that will be copied into a GPU buffer.
///
/// This corresponds to the `#[data]` attribute in `AsBindGroup`.
#[derive(Debug, Deref, DerefMut)]
pub struct OwnedData(pub Vec<u8>);
impl OwnedBindingResource {
/// Creates a [`BindingResource`] reference to this
/// [`OwnedBindingResource`].
///
/// Note that this operation panics if passed a
/// [`OwnedBindingResource::Data`], because [`OwnedData`] doesn't itself
/// correspond to any binding and instead requires the
/// `MaterialBindGroupAllocator` to pack it into a buffer.
pub fn get_binding(&self) -> BindingResource<'_> {
match self {
OwnedBindingResource::Buffer(buffer) => buffer.as_entire_binding(),
OwnedBindingResource::ShaderBuffer(_) => {
panic!(
"You can't use `get_binding` with a `ShaderBuffer`; fetch the buffer from \
the `RenderAssets<GpuShaderBuffer>` instead"
)
}
OwnedBindingResource::TextureView(_, view) => BindingResource::TextureView(view),
OwnedBindingResource::Sampler(_, sampler) => BindingResource::Sampler(sampler),
OwnedBindingResource::Data(_) => panic!("`OwnedData` has no binding resource"),
}
}
}
impl UnpreparedBindingResource {
/// Creates a [`BindingResource`] reference to this
/// [`UnpreparedBindingResource`].
///
/// Note that this operation panics if passed a
/// [`UnpreparedBindingResource::Data`], because the range doesn't itself
/// correspond to any binding and instead requires theView on GitHub (pinned to 396ca72708)
Solutions
- Match the variant: for ShaderBuffer, look the GPU buffer up in RenderAssets<GpuShaderBuffer> by its id and bind gpu.buffer via BufferBinding.
- Restructure code so get_binding() is only called on variants that have a direct binding (Buffer, TextureView, Sampler).
- Reuse the engine's material preparation, which already routes ShaderBuffer correctly.
Example fix
// before
let binding = owned_resource.get_binding(); // panics on ShaderBuffer variant
// after
let binding = match &owned_resource {
OwnedBindingResource::ShaderBuffer(buffer) => {
let gpu = gpu_shader_buffers.get(buffer.id()).expect("GpuShaderBuffer prepared");
BindingResource::Buffer(BufferBinding { buffer: &gpu.buffer, offset: 0, size: None })
}
other => other.get_binding(),
}; Defensive patterns
Strategy: type-guard
Type guard
fn has_direct_binding(res: &OwnedBindingResource) -> bool {
!matches!(
res,
OwnedBindingResource::ShaderBuffer(_) | OwnedBindingResource::Data(_)
)
} Prevention
- Never call get_binding() blindly; match on the variant first.
- For ShaderBuffer, resolve the GPU buffer from RenderAssets<GpuShaderBuffer> by id.
- Prefer the engine's material preparation, which routes ShaderBuffer correctly.
When it happens
Trigger: Calling get_binding() (directly or from generic code iterating OwnedBindingResource values) on a value that is OwnedBindingResource::ShaderBuffer - typical in custom AsBindGroup implementations or hand-built bind groups.
Common situations: Custom material/bind-group code that treats all owned binding resources uniformly; migrating buffer-based bindings to ShaderBuffer; bindless or slotted material paths where shader buffers are packed elsewhere.
Related errors
- `OwnedData` has no binding resource
- Data ranges have no binding resource
- Failed to get buffer
- Failed to get buffer
- Cannot call `ReflectComponent::reflect_mut` on component {na
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/33a39985d0212aee.
Report an issue: GitHub.