diff --git a/src/path/path-util.cpp b/src/path/path-util.cpp index 118dda421debcf20d15594187e643da69050b940..c8af3e0e03254acafc7e514f8655a9e9574bac54 100644 --- a/src/path/path-util.cpp +++ b/src/path/path-util.cpp @@ -170,9 +170,13 @@ std::unique_ptr curve_for_item_before_LPE(SPItem *item) std::optional get_nearest_position_on_Path(Path *path, Geom::Point p, unsigned seg) { + std::optional result; + if (!path) { + return result; // returns empty std::optional + } //get nearest position on path - Path::cut_position pos = path->PointToCurvilignPosition(p, seg); - return pos; + result = path->PointToCurvilignPosition(p, seg); + return result; } Geom::Point get_point_on_Path(Path *path, int piece, double t) diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp index a99e5b51dd9d67a81a8e118af0269f2161d0f20c..19fe5d4f4d885e8c1e3d7b10e4a94378c2273fdc 100644 --- a/src/ui/tools/calligraphic-tool.cpp +++ b/src/ui/tools/calligraphic-tool.cpp @@ -486,7 +486,9 @@ bool CalligraphicTool::root_handler(GdkEvent* event) { if (this->hatch_livarot_path) delete this->hatch_livarot_path; this->hatch_livarot_path = Path_for_item (this->hatch_item, true, true); - this->hatch_livarot_path->ConvertWithBackData(0.01); + if (hatch_livarot_path) { + hatch_livarot_path->ConvertWithBackData(0.01); + } } // calculate pointer point in the guide item's coords @@ -495,15 +497,16 @@ bool CalligraphicTool::root_handler(GdkEvent* event) { // calculate the nearest point on the guide path std::optional position = get_nearest_position_on_Path(this->hatch_livarot_path, pointer); - nearest = get_point_on_Path(this->hatch_livarot_path, position->piece, position->t); - + if (position) { + nearest = get_point_on_Path(hatch_livarot_path, position->piece, position->t); - // distance from pointer to nearest - hatch_dist = Geom::L2(pointer - nearest); - // unit-length vector - hatch_unit_vector = (pointer - nearest)/hatch_dist; + // distance from pointer to nearest + hatch_dist = Geom::L2(pointer - nearest); + // unit-length vector + hatch_unit_vector = (pointer - nearest) / hatch_dist; - this->message_context->set(Inkscape::NORMAL_MESSAGE, _("Guide path selected; start drawing along the guide with Ctrl")); + this->message_context->set(Inkscape::NORMAL_MESSAGE, _("Guide path selected; start drawing along the guide with Ctrl")); + } } else { this->message_context->set(Inkscape::NORMAL_MESSAGE, _("Select a guide path to track with Ctrl")); }