From 79b1a844d2efcc1b4c7acf43c27c97aa3accd8da Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 28 May 2015 18:59:09 +0300 Subject: [PATCH] Temporary fix, which will be corrected by MPV. Crash fix: Create circle, translation, Undo, Redo. The reason is that SketchPlugin_Circle::execute() flushes redisplay on 1st result creation. SketcerPrs listen it and obtains all results in the references list. The 2nd result is not created yet and it leads to crash. --- src/SketchPlugin/SketchPlugin_Circle.cpp | 29 +++++++++---------- src/SketcherPrs/SketcherPrs_Mirror.cpp | 12 ++++++++ .../SketcherPrs_Transformation.cpp | 6 ++++ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index 8625d578b..1b74f50ee 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -55,22 +55,19 @@ void SketchPlugin_Circle::execute() // make a visible circle std::shared_ptr aNDir = std::dynamic_pointer_cast( - aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); - bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0); - if (aHasPlane) { - std::shared_ptr aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z())); - // compute the circle radius - double aRadius = aRadiusAttr->value(); - - std::shared_ptr aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle( - aCenter, aNormal, aRadius); - aShapes.push_back(aCircleShape); - std::shared_ptr aConstr2 = document()->createConstruction( - data(), 1); - aConstr2->setShape(aCircleShape); - aConstr2->setIsInHistory(false); - setResult(aConstr2, 1); - } + aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); + std::shared_ptr aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z())); + // compute the circle radius + double aRadius = aRadiusAttr->value(); + + std::shared_ptr aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle( + aCenter, aNormal, aRadius); + aShapes.push_back(aCircleShape); + std::shared_ptr aConstr2 = document()->createConstruction( + data(), 1); + aConstr2->setShape(aCircleShape); + aConstr2->setIsInHistory(false); + setResult(aConstr2, 1); } } } diff --git a/src/SketcherPrs/SketcherPrs_Mirror.cpp b/src/SketcherPrs/SketcherPrs_Mirror.cpp index 2c680a64a..dca445bfd 100644 --- a/src/SketcherPrs/SketcherPrs_Mirror.cpp +++ b/src/SketcherPrs/SketcherPrs_Mirror.cpp @@ -52,11 +52,23 @@ bool SketcherPrs_Mirror::updatePoints(double theStep) const gp_Pnt aP1; for (i = 0; i < aNb; i++) { aObj = anAttrB->object(i); + if (!aObj.get()) // TODO:empty_result + // this check should be removed here after the result flush is corrected + // the problem is, that feature::execute() flushes redisplay by each result creation + // but it is possible(e.g. in the sketch circle, that there should be more than one result. + // Here, crash happens, because the second result is not created yet + continue; aP1 = aMgr->getPosition(aObj, this, theStep); myPntArray->SetVertice(i + 1, aP1); } for (i = 0; i < aNb; i++) { aObj = anAttrC->object(i); + if (!aObj.get()) // TODO:empty_result + // this check should be removed here after the result flush is corrected + // the problem is, that feature::execute() flushes redisplay by each result creation + // but it is possible(e.g. in the sketch circle, that there should be more than one result. + // Here, crash happens, because the second result is not created yet + continue; aP1 = aMgr->getPosition(aObj, this, theStep); myPntArray->SetVertice(aNb + i + 1, aP1); } diff --git a/src/SketcherPrs/SketcherPrs_Transformation.cpp b/src/SketcherPrs/SketcherPrs_Transformation.cpp index dcbe96667..47f32f7b5 100644 --- a/src/SketcherPrs/SketcherPrs_Transformation.cpp +++ b/src/SketcherPrs/SketcherPrs_Transformation.cpp @@ -47,6 +47,12 @@ bool SketcherPrs_Transformation::updatePoints(double theStep) const gp_Pnt aP1; for (i = 0; i < aNbB; i++) { aObj = anAttrB->object(i); + if (!aObj.get()) // TODO:empty_result + // this check should be removed here after the result flush is corrected + // the problem is, that feature::execute() flushes redisplay by each result creation + // but it is possible(e.g. in the sketch circle, that there should be more than one result. + // Here, crash happens, because the second result is not created yet + continue; aP1 = aMgr->getPosition(aObj, this, theStep); myPntArray->SetVertice(i + 1, aP1); } -- 2.39.2