From 842421ea61562f10ca932bf19b902202438789a7 Mon Sep 17 00:00:00 2001 From: kobewi Date: Wed, 12 Feb 2025 17:43:53 +0100 Subject: [PATCH] Prevent errors when Line2D has 0 length --- scene/2d/line_2d.cpp | 3 +++ scene/2d/line_builder.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp index d165d477f8..f27d729e21 100644 --- a/scene/2d/line_2d.cpp +++ b/scene/2d/line_2d.cpp @@ -299,6 +299,9 @@ void Line2D::_draw() { } lb.build(); + if (lb.indices.is_empty()) { + return; + } RS::get_singleton()->canvas_item_add_triangle_array( get_canvas_item(), diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp index ea949712ee..4a092675c9 100644 --- a/scene/2d/line_builder.cpp +++ b/scene/2d/line_builder.cpp @@ -112,6 +112,11 @@ void LineBuilder::build() { } } + if (Math::is_zero_approx(total_distance)) { + // Zero-length line, nothing to build. + return; + } + if (_interpolate_color) { color0 = gradient->get_color(0); } else {