From bf85140b652d5cc7b4361354fb20aaf33563fa0b Mon Sep 17 00:00:00 2001 From: Schmarni Date: Sun, 31 Aug 2025 05:42:07 +0200 Subject: [PATCH] fix(lines): add a check to prevent a crash Signed-off-by: Schmarni --- src/nodes/drawable/lines.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/nodes/drawable/lines.rs b/src/nodes/drawable/lines.rs index 06348b0..700c4b9 100644 --- a/src/nodes/drawable/lines.rs +++ b/src/nodes/drawable/lines.rs @@ -194,14 +194,16 @@ fn build_line_mesh( } indices_set += 1; } - // Handle the connection between start and end points: - // - For cyclic lines: connect last segment back to first - // - For non-cyclic lines: add caps at both ends - if line.cyclic { - vertex_indices.extend(cyclic_indices(start_set, indices_set - 1)); - } else { - vertex_indices.extend(cap_indices(start_set, false)); - vertex_indices.extend(cap_indices(indices_set - 1, true)); + if indices_set > 0 { + // Handle the connection between start and end points: + // - For cyclic lines: connect last segment back to first + // - For non-cyclic lines: add caps at both ends + if line.cyclic { + vertex_indices.extend(cyclic_indices(start_set, indices_set - 1)); + } else { + vertex_indices.extend(cap_indices(start_set, false)); + vertex_indices.extend(cap_indices(indices_set - 1, true)); + } } } let mut mesh = Mesh::new(