{"record":{"id":"33a39985d0212aee","repo":"bevyengine/bevy","slug":"you-can-t-use-get-binding-with-a-shaderbuffer","errorCode":null,"errorMessage":"You can't use `get_binding` with a `ShaderBuffer`; fetch the buffer from the `RenderAssets<GpuShaderBuffer>` instead","messagePattern":"You can't use `get_binding` with a `ShaderBuffer`; fetch the buffer from the `RenderAssets<GpuShaderBuffer>` instead","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/bevy_render/src/render_resource/bind_group.rs","lineNumber":825,"sourceCode":"/// Data that will be copied into a GPU buffer.\n///\n/// This corresponds to the `#[data]` attribute in `AsBindGroup`.\n#[derive(Debug, Deref, DerefMut)]\npub struct OwnedData(pub Vec<u8>);\n\nimpl OwnedBindingResource {\n    /// Creates a [`BindingResource`] reference to this\n    /// [`OwnedBindingResource`].\n    ///\n    /// Note that this operation panics if passed a\n    /// [`OwnedBindingResource::Data`], because [`OwnedData`] doesn't itself\n    /// correspond to any binding and instead requires the\n    /// `MaterialBindGroupAllocator` to pack it into a buffer.\n    pub fn get_binding(&self) -> BindingResource<'_> {\n        match self {\n            OwnedBindingResource::Buffer(buffer) => buffer.as_entire_binding(),\n            OwnedBindingResource::ShaderBuffer(_) => {\n                panic!(\n                    \"You can't use `get_binding` with a `ShaderBuffer`; fetch the buffer from \\\n                     the `RenderAssets<GpuShaderBuffer>` instead\"\n                )\n            }\n            OwnedBindingResource::TextureView(_, view) => BindingResource::TextureView(view),\n            OwnedBindingResource::Sampler(_, sampler) => BindingResource::Sampler(sampler),\n            OwnedBindingResource::Data(_) => panic!(\"`OwnedData` has no binding resource\"),\n        }\n    }\n}\n\nimpl UnpreparedBindingResource {\n    /// Creates a [`BindingResource`] reference to this\n    /// [`UnpreparedBindingResource`].\n    ///\n    /// Note that this operation panics if passed a\n    /// [`UnpreparedBindingResource::Data`], because the range doesn't itself\n    /// correspond to any binding and instead requires the","sourceCodeStart":807,"sourceCodeEnd":843,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_render/src/render_resource/bind_group.rs#L807-L843","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nlet binding = owned_resource.get_binding(); // panics on ShaderBuffer variant\n\n// after\nlet binding = match &owned_resource {\n    OwnedBindingResource::ShaderBuffer(buffer) => {\n        let gpu = gpu_shader_buffers.get(buffer.id()).expect(\"GpuShaderBuffer prepared\");\n        BindingResource::Buffer(BufferBinding { buffer: &gpu.buffer, offset: 0, size: None })\n    }\n    other => other.get_binding(),\n};","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn has_direct_binding(res: &OwnedBindingResource) -> bool {\n    !matches!(\n        res,\n        OwnedBindingResource::ShaderBuffer(_) | OwnedBindingResource::Data(_)\n    )\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["bevy","shader-buffer","binding","panic","bind-group"],"backgroundTag":"unsupported-variant-access","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}