Skip to content

Commit 8024168

Browse files
authored
Correctly check cpu data size not just descriptor. (#22612)
# Objective Fixes #22609. ## Solution We need to also validate the cpu data size before we do any copies, etc. We'll ignore the users descriptor size if the configured it wrong. Not sure if we want to to warn or if there's any scenario where overwriting the size wouldn't be the right call. ## Testing `fps_overlay` no longer crashes.
1 parent bb10502 commit 8024168

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

crates/bevy_render/src/storage.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,18 @@ impl RenderAsset for GpuShaderBuffer {
164164
) -> Result<Self, PrepareAssetError<Self::SourceAsset>> {
165165
let had_data = source_asset.data.is_some();
166166

167+
// when cpu data is provided, the actual buffer size is determined by the vec length,
168+
// not the descriptor size
169+
let actual_size = source_asset
170+
.data
171+
.as_ref()
172+
.map(|d| d.len() as u64)
173+
.unwrap_or(source_asset.buffer_description.size);
174+
167175
let buffer = if let Some(prev) = previous_asset
168-
&& prev.buffer_descriptor == source_asset.buffer_description
176+
&& prev.buffer_descriptor.size == actual_size
177+
&& prev.buffer_descriptor.usage == source_asset.buffer_description.usage
178+
&& prev.buffer_descriptor.label == source_asset.buffer_description.label
169179
&& source_asset
170180
.buffer_description
171181
.usage
@@ -210,7 +220,10 @@ impl RenderAsset for GpuShaderBuffer {
210220

211221
Ok(GpuShaderBuffer {
212222
buffer,
213-
buffer_descriptor: source_asset.buffer_description,
223+
buffer_descriptor: wgpu::BufferDescriptor {
224+
size: actual_size,
225+
..source_asset.buffer_description
226+
},
214227
had_data,
215228
})
216229
}

0 commit comments

Comments
 (0)