fix Default implementation of Image so that size and data match (#2833)

Before using this image resulted in an `Error in Queue::write_texture: copy of 0..4 would end up overrunning the bounds of the Source buffer of size 0`
This commit is contained in:
Jakob Hellermann 2021-09-16 22:50:21 +00:00
parent 52fd626fed
commit 1e03a97e73

View File

@ -3,6 +3,7 @@ use crate::{
render_asset::RenderAsset, render_asset::RenderAsset,
render_resource::{Sampler, Texture, TextureView}, render_resource::{Sampler, Texture, TextureView},
renderer::{RenderDevice, RenderQueue}, renderer::{RenderDevice, RenderQueue},
texture::BevyDefault,
}; };
use bevy_reflect::TypeUuid; use bevy_reflect::TypeUuid;
use thiserror::Error; use thiserror::Error;
@ -25,15 +26,17 @@ pub struct Image {
impl Default for Image { impl Default for Image {
fn default() -> Self { fn default() -> Self {
let format = wgpu::TextureFormat::bevy_default();
let data = vec![1; format.pixel_size() as usize];
Image { Image {
data: Default::default(), data,
texture_descriptor: wgpu::TextureDescriptor { texture_descriptor: wgpu::TextureDescriptor {
size: wgpu::Extent3d { size: wgpu::Extent3d {
width: 1, width: 1,
height: 1, height: 1,
depth_or_array_layers: 1, depth_or_array_layers: 1,
}, },
format: wgpu::TextureFormat::Rgba8UnormSrgb, format,
dimension: wgpu::TextureDimension::D2, dimension: wgpu::TextureDimension::D2,
label: None, label: None,
mip_level_count: 1, mip_level_count: 1,