From 518426fb8ed78a69d8c13db143e9c79df92b181b Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Mon, 19 Jun 2017 19:12:43 +0300 Subject: [PATCH] Create 1-byte buffer on empty input data --- vulkano/src/buffer/cpu_access.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vulkano/src/buffer/cpu_access.rs b/vulkano/src/buffer/cpu_access.rs index bf3a55c2..d1505e4a 100644 --- a/vulkano/src/buffer/cpu_access.rs +++ b/vulkano/src/buffer/cpu_access.rs @@ -124,17 +124,18 @@ impl CpuAccessibleBuffer { impl CpuAccessibleBuffer<[T]> { /// Builds a new buffer that contains an array `T`. The initial data comes from an iterator /// that produces that list of Ts. - /// # Panics - /// Panics if the initial data is empty. pub fn from_iter<'a, I, Q>(device: Arc, usage: BufferUsage, queue_families: Q, data: I) -> Result>, OomError> where I: ExactSizeIterator, T: Content + 'static, Q: IntoIterator> { - assert_ne!(data.len(), 0, "Tried to create buffer from empty iterator."); - unsafe { + // To avoid panicking on empty input data, create a 1-byte uninitialized buffer. + if data.len() == 0 { + return CpuAccessibleBuffer::uninitialized_array(device, 1, usage, queue_families); + }; + let uninitialized = try!( CpuAccessibleBuffer::uninitialized_array(device, data.len(), usage, queue_families) );