{"record":{"id":"6196eb3dd068ab9e","repo":"bevyengine/bevy","slug":"failed-to-get-buffer-6196eb","errorCode":null,"errorMessage":"Failed to get buffer","messagePattern":"Failed to get buffer","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_render/src/render_resource/uniform_buffer.rs","lineNumber":149,"sourceCode":"\n        if self.changed || self.buffer.is_none() {\n            self.buffer = Some(device.create_buffer_with_data(&BufferInitDescriptor {\n                label: make_buffer_label::<Self>(&self.label),\n                usage: self.buffer_usage,\n                contents: self.scratch.as_ref(),\n            }));\n            self.changed = false;\n        } else if let Some(buffer) = &self.buffer {\n            queue.write_buffer(buffer, 0, self.scratch.as_ref());\n        }\n    }\n}\n\nimpl<'a, T: ShaderType + WriteInto> IntoBinding<'a> for &'a UniformBuffer<T> {\n    #[inline]\n    fn into_binding(self) -> BindingResource<'a> {\n        self.buffer()\n            .expect(\"Failed to get buffer\")\n            .as_entire_buffer_binding()\n            .into_binding()\n    }\n}\n\n/// Stores data to be transferred to the GPU and made accessible to shaders as a dynamic uniform buffer.\n///\n/// Dynamic uniform buffers are available to shaders on a read-only basis. Dynamic uniform buffers are commonly used to make\n/// available to shaders runtime-sized arrays of parameters that are otherwise constant during shader execution, and are best\n/// suited to data that is relatively small in size as they are only guaranteed to support up to 16kB per binding.\n///\n/// The contained data is stored in system RAM. [`write_buffer`](DynamicUniformBuffer::write_buffer) queues\n/// copying of the data from system RAM to VRAM. Data in uniform buffers must follow [std140 alignment/padding requirements],\n/// which is automatically enforced by this structure. Per the WGPU spec, uniform buffers cannot store runtime-sized array\n/// (vectors), or structures with fields that are vectors.\n///\n/// Other options for storing GPU-accessible data are:\n/// * [`BufferVec`](crate::render_resource::BufferVec)","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_render/src/render_resource/uniform_buffer.rs#L131-L167","documentation":"IntoBinding for &UniformBuffer<T> calls self.buffer().expect(\"Failed to get buffer\"). buffer() returns Option<&Buffer> that is None until write_buffer() allocates the GPU buffer on the first write. Binding a UniformBuffer via IntoBinding before any write_buffer() call panics with this message.","triggerScenarios":"Using &uniform_buffer as BindingResource (BindGroupEntries / entries.add(&uniform_buffer)) before UniformBuffer::write_buffer(&queue) ran — e.g. the bind-group system runs before the uniform-writing system, or the value was never set.","commonSituations":"View/projection uniform buffers built in ExtractedView-style systems while the bind group is created in an unordered sibling system; first-frame access; new code path that sets the value conditionally so write_buffer is skipped.","solutions":["Call uniform_buffer.write_buffer(&queue) in a system that runs before bind-group construction","Make sure the value is set (set()) so the first write actually uploads and allocates","Check uniform_buffer.buffer().is_some() (or .binding().is_some()) before building the bind group and skip otherwise"],"exampleFix":"// before\nfn make_bind_group(ub: &UniformBuffer Globals>, ...) {\n    let entries = BindGroupEntries::sequential([&ub]); // panics\n}\n\n// after\nfn upload_globals(ub: &mut UniformBuffer<Globals>, queue: &RenderQueue) {\n    ub.write_buffer(queue); // first call allocates\n}\nfn make_bind_group(ub: &UniformBuffer<Globals>, ...) {\n    let Some(binding) = ub.binding() else { return; };\n    // build bind group with `binding`\n}","handlingStrategy":"validation","validationCode":"// Before IntoBinding / bind-group construction:\nif uniform_buffer.buffer().is_none() {\n    // value never written: call ub.write_buffer(&queue) first\n    return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set and write the uniform in a system ordered before the one that binds it","Use binding() (Option<BindingResource>) for first-frame-safe bind-group code","Initialize uniform values in plugin build/first extraction so the first write_buffer happens early"],"tags":["bevy","uniform-buffer","gpu-buffer","binding","panic"],"backgroundTag":"gpu-buffer-not-initialized","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}