{"record":{"id":"f33647e9f85fac57","repo":"bevyengine/bevy","slug":"buffernotinitialized","errorCode":"BufferNotInitialized","errorMessage":"the gpu buffer is not initialized","messagePattern":"the gpu buffer is not initialized","errorType":"error_code","errorClass":"WriteBufferRangeError","httpStatus":null,"severity":"error","filePath":"crates/bevy_render/src/render_resource/buffer_vec.rs","lineNumber":982,"sourceCode":"    T: NoUninit + Default,\n{\n    /// Pushes `count` copies of `T::default` to the array.\n    pub fn push_multiple_init(&mut self, count: usize) -> usize {\n        debug_assert_eq!(self.uninit_element_count, 0);\n        let index = self.values.len();\n        self.values.extend(iter::repeat_n(T::default(), count));\n        index\n    }\n}\n\n/// Error returned when `write_buffer_range` fails\n///\n/// See [`RawBufferVec::write_buffer_range`] [`BufferVec::write_buffer_range`]\n#[derive(Debug, Eq, PartialEq, Copy, Clone, Error)]\npub enum WriteBufferRangeError {\n    #[error(\"the range is bigger than the capacity of the buffer\")]\n    RangeBiggerThanBuffer,\n    #[error(\"the gpu buffer is not initialized\")]\n    BufferNotInitialized,\n    #[error(\"there are no values to upload\")]\n    NoValuesToUpload,\n}\n\n#[inline]\n#[cfg_attr(\n    not(feature = \"type_label_buffers\"),\n    expect(\n        clippy::extra_unused_type_parameters,\n        reason = \"conditional compilation\"\n    )\n)]\npub(crate) fn make_buffer_label<'a, T>(label: &'a Option<String>) -> Option<&'a str> {\n    #[cfg(feature = \"type_label_buffers\")]\n    if label.is_none() {\n        return Some(core::any::type_name::<T>());\n    }","sourceCodeStart":964,"sourceCodeEnd":1000,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_render/src/render_resource/buffer_vec.rs#L964-L1000","documentation":"WriteBufferRangeError::BufferNotInitialized is returned when write_buffer_range is called while the underlying wgpu buffer is None (buffer_vec.rs:212-213): the GPU buffer was never created because neither write_buffer() nor reserve() has run yet. Partial-range writes can only be queued onto an existing buffer.","triggerScenarios":"Constructing a fresh BufferVec/RawBufferVec, pushing values, and calling write_buffer_range before any write_buffer(render_device, queue) or reserve(n, render_device) call created the GPU buffer.","commonSituations":"New render features with lazily-populated buffers; system ordering where a partial-update system runs before the buffer-creating system; buffers reused across frames but cleared in a way that drops the GPU buffer.","solutions":["Initialize first: call vec.write_buffer(render_device, render_queue) once (creates and fills the buffer), or reserve(n, render_device).","Order systems so the buffer-creating write happens before any partial-range updates (add explicit system ordering).","Match on the error and initialize on demand before retrying."],"exampleFix":"// before\nlet mut vec = RawBufferVec::default();\nvec.push(value);\nvec.write_buffer_range(queue, 0..1)?; // Err: buffer is None\n\n// after\nif vec.buffer().is_none() {\n    vec.write_buffer(render_device, queue); // creates the GPU buffer\n}\nvec.write_buffer_range(queue, 0..1)?;","handlingStrategy":"validation","validationCode":"if vec.buffer().is_none() {\n    vec.write_buffer(render_device, render_queue); // create the GPU buffer first\n}\nvec.write_buffer_range(queue, 0..vec.len())?;","typeGuard":null,"tryCatchPattern":"match vec.write_buffer_range(queue, 0..vec.len()) {\n    Err(WriteBufferRangeError::BufferNotInitialized) => {\n        vec.write_buffer(render_device, render_queue); // init, then retry\n        vec.write_buffer_range(queue, 0..vec.len())?\n    }\n    other => other?,\n}","preventionTips":["Call write_buffer() or reserve() once when the BufferVec is created or first populated.","Order buffer-creation systems before partial-update systems with explicit ordering constraints.","Treat a None buffer as 'not yet on the GPU', not as an empty one."],"tags":["bevy","buffer-vec","initialization","gpu-upload"],"backgroundTag":"resource-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"}