Skip to content
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

TrackedRenderPass::set_vertex_buffer does not update if the size of sliced buffer changed #14841

Closed
akimakinai opened this issue Aug 21, 2024 · 0 comments · Fixed by #14916
Closed
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Needs-Investigation This issue requires detective work to figure out what's going wrong

Comments

@akimakinai
Copy link
Contributor

akimakinai commented Aug 21, 2024

Bevy version

0.14.1

What you did

In #14721, I set a slice of seemingly correct size as a vertex buffer and got errors like Instance 555 extends beyond limit 554 imposed by the buffer in slot 3.

What went wrong

In this case, the same underlying buffer is used as vertex buffer with the same offset but different sizes (slice(item_size..) vs slice(item_size..buf_size)) from two draw functions.
It looks like TrackedRenderPass::set_vertex_buffer returns without updating the vertex buffer if buffer and offset matches, ignoring its size.

pub fn set_vertex_buffer(&mut self, slot_index: usize, buffer_slice: BufferSlice<'a>) {
let offset = buffer_slice.offset();
if self
.state
.is_vertex_buffer_set(slot_index, buffer_slice.id(), offset)
{
detailed_trace!(
"set vertex buffer {} (already set): {:?} ({})",
slot_index,
buffer_slice.id(),
offset
);
return;
}

pub fn is_vertex_buffer_set(&self, index: usize, buffer: BufferId, offset: u64) -> bool {
if let Some(current) = self.vertex_buffers.get(index) {
*current == Some((buffer, offset))
} else {
false
}
}

@akimakinai akimakinai added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Aug 21, 2024
@TrialDragon TrialDragon added A-Rendering Drawing game state to the screen S-Needs-Investigation This issue requires detective work to figure out what's going wrong and removed S-Needs-Triage This issue needs to be labelled labels Aug 23, 2024
github-merge-queue bot pushed a commit that referenced this issue Aug 28, 2024
# Objective

- Fixes #14841

## Solution

- Compute BufferSlice size manually and use it for comparison in
`TrackedRenderPass`

## Testing

- Gizmo example does not crash with #14721 (without system ordering),
and `slice` computes correct size there

---

## Migration Guide

- `TrackedRenderPass::set_vertex_buffer` function has been modified to
update vertex buffers when the same buffer with the same offset is
provided, but its size has changed. Some existing code may rely on the
previous behavior, which did not update the vertex buffer in this
scenario.

---------

Co-authored-by: Zachary Harrold <zac@harrold.com.au>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Needs-Investigation This issue requires detective work to figure out what's going wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants