From d30eb39a1e6da0ac6b1f251b6c4877ff2d44f3fd Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 9 Nov 2014 17:59:54 +0100 Subject: [PATCH] + fixes #0001808: Double Clicking Sketcher PolyLine Causing Crash --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 40 ++++++++++++++++------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index f32e03f8c..db7e1c9c3 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -802,6 +803,7 @@ public: resetPositionText(); sketchgui->drawEdit(EditCurve); sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider + return true; // 'this' instance is destroyed now! } Mode = STATUS_Do; @@ -824,15 +826,22 @@ public: virtual bool releaseButton(Base::Vector2D onSketchPos) { if (Mode == STATUS_Do || Mode == STATUS_Close) { - + bool addedGeometry = true; if (SegmentMode == SEGMENT_MODE_Line) { // open the transaction Gui::Command::openCommand("Add line to sketch wire"); // issue the geometry - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.Line(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))", - sketchgui->getObject()->getNameInDocument(), - EditCurve[0].fX,EditCurve[0].fY,EditCurve[1].fX,EditCurve[1].fY); + try { + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.addGeometry(Part.Line(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))", + sketchgui->getObject()->getNameInDocument(), + EditCurve[0].fX,EditCurve[0].fY,EditCurve[1].fX,EditCurve[1].fY); + } + catch (const Base::Exception& e) { + addedGeometry = false; + Base::Console().Error("Failed to add line: %s\n", e.what()); + Gui::Command::abortCommand(); + } } else if (SegmentMode == SEGMENT_MODE_Arc) { // We're dealing with an Arc if (!boost::math::isnormal(arcRadius)) { @@ -840,15 +849,22 @@ public: return true; } Gui::Command::openCommand("Add arc to sketch wire"); - Gui::Command::doCommand(Gui::Command::Doc, - "App.ActiveDocument.%s.addGeometry(Part.ArcOfCircle" - "(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),%f),%f,%f))", - sketchgui->getObject()->getNameInDocument(), - CenterPoint.fX, CenterPoint.fY, std::abs(arcRadius), - std::min(startAngle,endAngle), std::max(startAngle,endAngle)); + try { + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.addGeometry(Part.ArcOfCircle" + "(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),%f),%f,%f))", + sketchgui->getObject()->getNameInDocument(), + CenterPoint.fX, CenterPoint.fY, std::abs(arcRadius), + std::min(startAngle,endAngle), std::max(startAngle,endAngle)); + } + catch (const Base::Exception& e) { + addedGeometry = false; + Base::Console().Error("Failed to add arc: %s\n", e.what()); + Gui::Command::abortCommand(); + } } // issue the constraint - if (previousPosId != Sketcher::none) { + if (addedGeometry && (previousPosId != Sketcher::none)) { int lastCurve = getHighestCurveIndex(); Sketcher::PointPos lastStartPosId = (SegmentMode == SEGMENT_MODE_Arc && startAngle > endAngle) ? Sketcher::end : Sketcher::start;