Skip to content

Commit

Permalink
bevy_render: Hack around empty storage buffer problem
Browse files Browse the repository at this point in the history
If there are no values, add a default one to avoid panics.
  • Loading branch information
superdump committed Feb 25, 2022
1 parent 72c8fb9 commit 9d9b13d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/bevy_render/src/render_resource/storage_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use crate::renderer::{RenderDevice, RenderQueue};

use super::Buffer;

pub struct StorageVec<T: AsStd430> {
pub struct StorageVec<T: AsStd430 + Default> {
values: Vec<T>,
scratch: Vec<u8>,
storage_buffer: Option<Buffer>,
capacity: usize,
item_size: usize,
}

impl<T: AsStd430> Default for StorageVec<T> {
impl<T: AsStd430 + Default> Default for StorageVec<T> {
fn default() -> Self {
Self {
values: Vec::new(),
Expand All @@ -30,7 +30,7 @@ impl<T: AsStd430> Default for StorageVec<T> {
}
}

impl<T: AsStd430> StorageVec<T> {
impl<T: AsStd430 + Default> StorageVec<T> {
#[inline]
pub fn storage_buffer(&self) -> Option<&Buffer> {
self.storage_buffer.as_ref()
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<T: AsStd430> StorageVec<T> {

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 {
Expand Down

0 comments on commit 9d9b13d

Please sign in to comment.