{"record":{"id":"2effd45558ff8642","repo":"bevyengine/bevy","slug":"rangebiggerthanbuffer","errorCode":"RangeBiggerThanBuffer","errorMessage":"the range is bigger than the capacity of the buffer","messagePattern":"the range is bigger than the capacity of the buffer","errorType":"error_code","errorClass":"WriteBufferRangeError","httpStatus":null,"severity":"error","filePath":"crates/bevy_render/src/render_resource/buffer_vec.rs","lineNumber":980,"sourceCode":"impl<T> PartialBufferVec<T>\nwhere\n    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() {","sourceCodeStart":962,"sourceCodeEnd":998,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_render/src/render_resource/buffer_vec.rs#L962-L998","documentation":"WriteBufferRangeError::RangeBiggerThanBuffer is returned by BufferVec/RawBufferVec::write_buffer_range when the requested range end exceeds the GPU buffer's capacity (item_size * capacity, checked at buffer_vec.rs:204). The CPU-side values vector grew past what was reserved on the GPU, so the requested bytes cannot be uploaded into the existing buffer.","triggerScenarios":"Pushing/extending values beyond the previously reserved GPU capacity, then calling write_buffer_range over a range that covers the new elements without calling reserve() first; or computing the range from a stale/incorrect length.","commonSituations":"Per-frame growth of instance/uniform/light buffers where capacity was reserved once at startup; clear()-then-regrow flows that forget to re-reserve; capacity computed from the wrong unit (elements vs bytes).","solutions":["Call vec.reserve(new_capacity, render_device) before writing once len exceeds capacity - note reserving reallocates the GPU buffer (values is the source of truth, so re-upload the full range).","Grow capacity geometrically (e.g. double it) to avoid reallocating every frame.","Double-check the range is expressed in element indices and stays within the reserved capacity."],"exampleFix":"// before\nvec.push(instance);\nvec.write_buffer_range(queue, 0..vec.len())?; // Err: len grew past GPU capacity\n\n// after\nif vec.len() > vec.capacity() {\n    vec.reserve(vec.len().max(vec.capacity() * 2), render_device);\n}\nvec.write_buffer_range(queue, 0..vec.len())?;","handlingStrategy":"validation","validationCode":"if vec.len() > vec.capacity() {\n    vec.reserve(vec.len().max(vec.capacity() * 2), render_device); // grow GPU capacity\n}\nvec.write_buffer_range(queue, 0..vec.len())?;","typeGuard":null,"tryCatchPattern":"match vec.write_buffer_range(queue, 0..vec.len()) {\n    Err(WriteBufferRangeError::RangeBiggerThanBuffer) => {\n        vec.reserve(vec.len().max(vec.capacity() * 2), render_device);\n        vec.write_buffer_range(queue, 0..vec.len())?; // retry after reserve\n    }\n    other => other?,\n}","preventionTips":["Reserve GPU capacity whenever the CPU-side vector grows (push/extend) before writing ranges.","Grow capacity geometrically to avoid per-frame reallocation.","Remember the range is element indices, and capacity is what you reserved - keep both in one place."],"tags":["bevy","buffer-vec","capacity","gpu-upload"],"backgroundTag":"buffer-capacity-exceeded","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"}