From b1fd2bc8d98dcbcc2c5ce83e95e37e260b384d43 Mon Sep 17 00:00:00 2001 From: Max Gaukler Date: Sat, 25 Apr 2020 19:39:33 +0200 Subject: [PATCH] Fix #217: Crash on shaping path with overlapping nodes If a path has the following structure: smooth segment -- "half-smooth node" (only left handle) -- line segment then we restrict shaping (dragging) the smooth segment so that the "half-smooth" node does not become a cusp node. If the line segment has zero length, then Inkscape crashes. This is difficult to trigger, even the "half-smooth" node is difficult to get: Use the Bezier tool, Click, Click-and-drag, then immediately click again without moving the mouse. Now you should have a smooth node with only one handle. A path of zero length can be made by manually changing the coordinates of the point. This patch avoids the crash; however, behavior in this ill-defined case is still somewhat odd. Partly, it's not even clear what the correct behavior should be. --- src/ui/tool/node.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index 83946bfaa0..3ad76e40d2 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -260,8 +260,14 @@ void Handle::move(Geom::Point const &new_pos) Geom::Point direction = _parent->position() - node_away->position(); Geom::Point delta = new_pos - _parent->position(); // project the relative position on the direction line - Geom::Point new_delta = (Geom::dot(delta, direction) - / Geom::L2sq(direction)) * direction; + Geom::Coord direction_length = Geom::L2sq(direction); + Geom::Point new_delta; + if (direction_length == 0) { + // joining line has zero length - any direction is okay, prevent division by zero + new_delta = delta; + } else { + new_delta = (Geom::dot(delta, direction) / direction_length) * direction; + } setRelativePos(new_delta); // move the handle and its opposite the same proportion -- GitLab