Skip to content

Fix many_foxes + motion blur = crash on WebGL #18715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions crates/bevy_pbr/src/render/skin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub fn prepare_skins(
// Swap current and previous buffers.
mem::swap(&mut uniform.current_buffer, &mut uniform.prev_buffer);

// Resize the buffer if necessary. Include extra space equal to `MAX_JOINTS`
// Resize the buffers if necessary. Include extra space equal to `MAX_JOINTS`
// because we need to be able to bind a full uniform buffer's worth of data
// if skins use uniform buffers on this platform.
let needed_size = (uniform.current_staging_buffer.len() as u64 + MAX_JOINTS as u64)
Expand All @@ -223,7 +223,7 @@ pub fn prepare_skins(
new_size += new_size / 2;
}

// Create a new buffer.
// Create the new buffers.
let buffer_usages = if skins_use_uniform_buffers(&render_device) {
BufferUsages::UNIFORM
} else {
Expand All @@ -235,6 +235,24 @@ pub fn prepare_skins(
size: new_size,
mapped_at_creation: false,
});
uniform.prev_buffer = render_device.create_buffer(&BufferDescriptor {
label: Some("skin uniform buffer"),
usage: buffer_usages,
size: new_size,
mapped_at_creation: false,
});

// We've created a new `prev_buffer` but we don't have the previous joint
// data needed to fill it out correctly. Use the current joint data
// instead.
//
// TODO: This is a bug - will cause motion blur to ignore joint movement
// for one frame.
render_queue.write_buffer(
&uniform.prev_buffer,
0,
bytemuck::must_cast_slice(&uniform.current_staging_buffer[..]),
);
}

// Write the data from `uniform.current_staging_buffer` into
Expand Down