fix: boundary check condition in renderstate (#7274)

This commit is contained in:
a.e. authored and GitHub committed 2025-10-14 19:25:27 +01:00
1 parent db5d743738
commit bb297506db
1 file changed
+6 -4
+6 -4
View File
@@ -308,16 +308,18 @@ impl<'a> QuadAllocator for MappedQuads<'a> {
fn extend_with(&mut self, vertices: &[Vertex]) {
let idx = *self.next;
let len = vertices.len();
// idx and next are number of quads, so divide by number of vertices
*self.next += vertices.len() / VERTICES_PER_CELL;
*self.next += len / VERTICES_PER_CELL;
// Only copy in if there is enough room.
// We'll detect the out of space condition at the end of
// the render pass.
let idx = idx * VERTICES_PER_CELL;
let len = self.capacity * VERTICES_PER_CELL;
if idx + vertices.len() < len {
let capacity = self.capacity * VERTICES_PER_CELL;
if idx + len <= capacity {
self.mapping
.slice_mut(idx..idx + vertices.len())
.slice_mut(idx..idx + len)
.copy_from_slice(vertices);
}
}