From a2fc835df3d0d32892f725a15a808006b17393fa Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Thu, 24 Feb 2022 16:11:12 +0100 Subject: [PATCH] bevy_render: Hack around empty storage buffer problem If there are no values, add a default one to avoid panics. --- crates/bevy_render/src/render_resource/storage_vec.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_render/src/render_resource/storage_vec.rs b/crates/bevy_render/src/render_resource/storage_vec.rs index e1d20dc760de0d..0d5d71e0f0b5b8 100644 --- a/crates/bevy_render/src/render_resource/storage_vec.rs +++ b/crates/bevy_render/src/render_resource/storage_vec.rs @@ -8,7 +8,7 @@ use crate::renderer::{RenderDevice, RenderQueue}; use super::Buffer; -pub struct StorageVec { +pub struct StorageVec { values: Vec, scratch: Vec, storage_buffer: Option, @@ -16,7 +16,7 @@ pub struct StorageVec { item_size: usize, } -impl Default for StorageVec { +impl Default for StorageVec { fn default() -> Self { Self { values: Vec::new(), @@ -30,7 +30,7 @@ impl Default for StorageVec { } } -impl StorageVec { +impl StorageVec { #[inline] pub fn storage_buffer(&self) -> Option<&Buffer> { self.storage_buffer.as_ref() @@ -89,7 +89,7 @@ impl StorageVec { pub fn write_buffer(&mut self, device: &RenderDevice, queue: &RenderQueue) { if self.values.is_empty() { - return; + self.values.push(T::default()); } self.reserve(self.values.len(), device); if let Some(storage_buffer) = &self.storage_buffer {