diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-02-17 00:29:40 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-02-17 00:29:40 +0100 |
commit | b8bab73d7e5615f114a705290786a3115e445af5 (patch) | |
tree | 1b63224ad5cc4dad4c836b2bf2a3d50a75b25297 | |
parent | 15a97a2e8462ff76fe2eb44094f61320065b7dc8 (diff) | |
parent | 4dfa161120308425877b350d6f8552b0d3d11c51 (diff) |
Merge pull request #73444 from bruvzg/dash_checks
Add dash and step size checks to draw_dashed_line.
-rw-r--r-- | scene/main/canvas_item.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index e5dcdd2afd..1c7d42ad36 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -515,12 +515,13 @@ void CanvasItem::draw_dashed_line(const Point2 &p_from, const Point2 &p_to, cons ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); float length = (p_to - p_from).length(); - if (length < p_dash) { + Vector2 step = p_dash * (p_to - p_from).normalized(); + + if (length < p_dash || step == Vector2() || p_dash <= 0.0) { RenderingServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width); return; } - Vector2 step = p_dash * (p_to - p_from).normalized(); int steps = (p_aligned) ? Math::ceil(length / p_dash) : Math::floor(length / p_dash); if (steps % 2 == 0) { steps--; |