From b522cce945722acb3c559c9046d9f647a32a633e Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 21 Apr 2016 14:35:19 +0300 Subject: [PATCH] #1404 Random crash with Shaper: AIS presentations: correction for symbol presentations. --- src/SketcherPrs/SketcherPrs_Collinear.cpp | 2 +- src/SketcherPrs/SketcherPrs_Collinear.h | 2 +- src/SketcherPrs/SketcherPrs_Equal.cpp | 2 +- src/SketcherPrs/SketcherPrs_Equal.h | 2 +- src/SketcherPrs/SketcherPrs_HVDirection.cpp | 2 +- src/SketcherPrs/SketcherPrs_HVDirection.h | 2 +- src/SketcherPrs/SketcherPrs_Middle.cpp | 2 +- src/SketcherPrs/SketcherPrs_Middle.h | 2 +- src/SketcherPrs/SketcherPrs_Mirror.cpp | 2 +- src/SketcherPrs/SketcherPrs_Mirror.h | 2 +- src/SketcherPrs/SketcherPrs_Parallel.cpp | 2 +- src/SketcherPrs/SketcherPrs_Parallel.h | 2 +- src/SketcherPrs/SketcherPrs_Perpendicular.cpp | 2 +- src/SketcherPrs/SketcherPrs_Perpendicular.h | 2 +- src/SketcherPrs/SketcherPrs_Rigid.cpp | 2 +- src/SketcherPrs/SketcherPrs_Rigid.h | 2 +- src/SketcherPrs/SketcherPrs_SymbolPrs.cpp | 16 +++++--- src/SketcherPrs/SketcherPrs_SymbolPrs.h | 2 +- src/SketcherPrs/SketcherPrs_Tangent.cpp | 2 +- src/SketcherPrs/SketcherPrs_Tangent.h | 2 +- src/SketcherPrs/SketcherPrs_Tools.cpp | 38 ++++++++++++++----- .../SketcherPrs_Transformation.cpp | 2 +- src/SketcherPrs/SketcherPrs_Transformation.h | 2 +- 23 files changed, 59 insertions(+), 37 deletions(-) diff --git a/src/SketcherPrs/SketcherPrs_Collinear.cpp b/src/SketcherPrs/SketcherPrs_Collinear.cpp index 64e027394..36c68a41d 100755 --- a/src/SketcherPrs/SketcherPrs_Collinear.cpp +++ b/src/SketcherPrs/SketcherPrs_Collinear.cpp @@ -44,7 +44,7 @@ bool SketcherPrs_Collinear::IsReadyToDisplay(ModelAPI_Feature* theConstraint, return aReadyToDisplay; } -bool SketcherPrs_Collinear::updatePoints(double theStep) const +bool SketcherPrs_Collinear::updateIfReadyToDisplay(double theStep) const { if (!IsReadyToDisplay(myConstraint, myPlane)) return false; diff --git a/src/SketcherPrs/SketcherPrs_Collinear.h b/src/SketcherPrs/SketcherPrs_Collinear.h index e43fdac89..61f55c0b0 100755 --- a/src/SketcherPrs/SketcherPrs_Collinear.h +++ b/src/SketcherPrs/SketcherPrs_Collinear.h @@ -41,7 +41,7 @@ protected: /// Update myPntArray according to presentation positions /// \return true in case of success - virtual bool updatePoints(double theStep) const; + virtual bool updateIfReadyToDisplay(double theStep) const; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Equal.cpp b/src/SketcherPrs/SketcherPrs_Equal.cpp index 1a808f935..4423ca592 100644 --- a/src/SketcherPrs/SketcherPrs_Equal.cpp +++ b/src/SketcherPrs/SketcherPrs_Equal.cpp @@ -44,7 +44,7 @@ bool SketcherPrs_Equal::IsReadyToDisplay(ModelAPI_Feature* theConstraint, return aReadyToDisplay; } -bool SketcherPrs_Equal::updatePoints(double theStep) const +bool SketcherPrs_Equal::updateIfReadyToDisplay(double theStep) const { if (!IsReadyToDisplay(myConstraint, myPlane)) return false; diff --git a/src/SketcherPrs/SketcherPrs_Equal.h b/src/SketcherPrs/SketcherPrs_Equal.h index bba05f150..0e0dd3130 100644 --- a/src/SketcherPrs/SketcherPrs_Equal.h +++ b/src/SketcherPrs/SketcherPrs_Equal.h @@ -41,7 +41,7 @@ protected: /// Update myPntArray according to presentation positions /// \return true in case of success - virtual bool updatePoints(double theStep) const; + virtual bool updateIfReadyToDisplay(double theStep) const; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_HVDirection.cpp b/src/SketcherPrs/SketcherPrs_HVDirection.cpp index bc9371240..23f68b7b1 100644 --- a/src/SketcherPrs/SketcherPrs_HVDirection.cpp +++ b/src/SketcherPrs/SketcherPrs_HVDirection.cpp @@ -40,7 +40,7 @@ bool SketcherPrs_HVDirection::IsReadyToDisplay(ModelAPI_Feature* theConstraint, return aReadyToDisplay; } -bool SketcherPrs_HVDirection::updatePoints(double theStep) const +bool SketcherPrs_HVDirection::updateIfReadyToDisplay(double theStep) const { if (!IsReadyToDisplay(myConstraint, myPlane)) return false; diff --git a/src/SketcherPrs/SketcherPrs_HVDirection.h b/src/SketcherPrs/SketcherPrs_HVDirection.h index 0f6bf64d3..39bd961a9 100644 --- a/src/SketcherPrs/SketcherPrs_HVDirection.h +++ b/src/SketcherPrs/SketcherPrs_HVDirection.h @@ -48,7 +48,7 @@ protected: /// Update myPntArray according to presentation positions /// \return true in case of success - virtual bool updatePoints(double theStep) const; + virtual bool updateIfReadyToDisplay(double theStep) const; private: bool myIsHorisontal; diff --git a/src/SketcherPrs/SketcherPrs_Middle.cpp b/src/SketcherPrs/SketcherPrs_Middle.cpp index eaba71733..4d4a00e15 100755 --- a/src/SketcherPrs/SketcherPrs_Middle.cpp +++ b/src/SketcherPrs/SketcherPrs_Middle.cpp @@ -45,7 +45,7 @@ bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint, return aReadyToDisplay; } -bool SketcherPrs_Middle::updatePoints(double theStep) const +bool SketcherPrs_Middle::updateIfReadyToDisplay(double theStep) const { if (!IsReadyToDisplay(myConstraint, myPlane)) return false; diff --git a/src/SketcherPrs/SketcherPrs_Middle.h b/src/SketcherPrs/SketcherPrs_Middle.h index 10d22ba86..0ba22c9f9 100755 --- a/src/SketcherPrs/SketcherPrs_Middle.h +++ b/src/SketcherPrs/SketcherPrs_Middle.h @@ -41,7 +41,7 @@ protected: /// Update myPntArray according to presentation positions /// \return true in case of success - virtual bool updatePoints(double theStep) const; + virtual bool updateIfReadyToDisplay(double theStep) const; /// Draw shape of the object. Find shape result if the object is feature void drawLine(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor, diff --git a/src/SketcherPrs/SketcherPrs_Mirror.cpp b/src/SketcherPrs/SketcherPrs_Mirror.cpp index a1fea6f4d..30bbc6ec3 100644 --- a/src/SketcherPrs/SketcherPrs_Mirror.cpp +++ b/src/SketcherPrs/SketcherPrs_Mirror.cpp @@ -57,7 +57,7 @@ bool SketcherPrs_Mirror::IsReadyToDisplay(ModelAPI_Feature* theConstraint, return aReadyToDisplay; } -bool SketcherPrs_Mirror::updatePoints(double theStep) const +bool SketcherPrs_Mirror::updateIfReadyToDisplay(double theStep) const { if (!IsReadyToDisplay(myConstraint, myPlane)) return false; diff --git a/src/SketcherPrs/SketcherPrs_Mirror.h b/src/SketcherPrs/SketcherPrs_Mirror.h index 35d5c146c..3d3d311e8 100644 --- a/src/SketcherPrs/SketcherPrs_Mirror.h +++ b/src/SketcherPrs/SketcherPrs_Mirror.h @@ -40,7 +40,7 @@ protected: /// Update myPntArray according to presentation positions /// \return true in case of success - virtual bool updatePoints(double theStep) const; + virtual bool updateIfReadyToDisplay(double theStep) const; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Parallel.cpp b/src/SketcherPrs/SketcherPrs_Parallel.cpp index 3a4d3be35..431c396b0 100644 --- a/src/SketcherPrs/SketcherPrs_Parallel.cpp +++ b/src/SketcherPrs/SketcherPrs_Parallel.cpp @@ -43,7 +43,7 @@ bool SketcherPrs_Parallel::IsReadyToDisplay(ModelAPI_Feature* theConstraint, return aReadyToDisplay; } -bool SketcherPrs_Parallel::updatePoints(double theStep) const +bool SketcherPrs_Parallel::updateIfReadyToDisplay(double theStep) const { if (!IsReadyToDisplay(myConstraint, myPlane)) return false; diff --git a/src/SketcherPrs/SketcherPrs_Parallel.h b/src/SketcherPrs/SketcherPrs_Parallel.h index e2d415fb7..cdadd0560 100644 --- a/src/SketcherPrs/SketcherPrs_Parallel.h +++ b/src/SketcherPrs/SketcherPrs_Parallel.h @@ -41,7 +41,7 @@ protected: /// Update myPntArray according to presentation positions /// \return true in case of success - virtual bool updatePoints(double theStep) const; + virtual bool updateIfReadyToDisplay(double theStep) const; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp index cb5302eef..58a7cdec8 100644 --- a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp @@ -43,7 +43,7 @@ bool SketcherPrs_Perpendicular::IsReadyToDisplay(ModelAPI_Feature* theConstraint return aReadyToDisplay; } -bool SketcherPrs_Perpendicular::updatePoints(double theStep) const +bool SketcherPrs_Perpendicular::updateIfReadyToDisplay(double theStep) const { if (!IsReadyToDisplay(myConstraint, myPlane)) return false; diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.h b/src/SketcherPrs/SketcherPrs_Perpendicular.h index 42bcf7953..33a6f7495 100644 --- a/src/SketcherPrs/SketcherPrs_Perpendicular.h +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.h @@ -46,7 +46,7 @@ protected: /// Update myPntArray according to presentation positions /// \return true in case of success - virtual bool updatePoints(double theStep) const; + virtual bool updateIfReadyToDisplay(double theStep) const; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Rigid.cpp b/src/SketcherPrs/SketcherPrs_Rigid.cpp index 71122d431..5875d6c29 100644 --- a/src/SketcherPrs/SketcherPrs_Rigid.cpp +++ b/src/SketcherPrs/SketcherPrs_Rigid.cpp @@ -68,7 +68,7 @@ bool SketcherPrs_Rigid::IsReadyToDisplay(ModelAPI_Feature* theConstraint, return aReadyToDisplay; } -bool SketcherPrs_Rigid::updatePoints(double theStep) const +bool SketcherPrs_Rigid::updateIfReadyToDisplay(double theStep) const { if (!IsReadyToDisplay(myConstraint, myPlane)) return false; diff --git a/src/SketcherPrs/SketcherPrs_Rigid.h b/src/SketcherPrs/SketcherPrs_Rigid.h index cf9d50427..1bb7b4a61 100644 --- a/src/SketcherPrs/SketcherPrs_Rigid.h +++ b/src/SketcherPrs/SketcherPrs_Rigid.h @@ -47,7 +47,7 @@ protected: /// Update myPntArray according to presentation positions /// \return true in case of success - virtual bool updatePoints(double theStep) const; + virtual bool updateIfReadyToDisplay(double theStep) const; }; diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp index 2d42f57a5..33c02b37c 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp @@ -362,10 +362,10 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& } // Update points with default shift value - if (!updatePoints(20)) { - Events_Error::throwException("An empty AIS presentation: SketcherPrs_SymbolPrs"); - return; - } + // it updates array of points if the presentation is ready to display, or the array of points + // contains the previous values + + bool aReadyToDisplay = updateIfReadyToDisplay(20); int aNbVertex = myPntArray->VertexNumber(); if (myOwner.IsNull()) { @@ -397,6 +397,10 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& // Disable frustum culling for this object by marking it as mutable aGroup->Structure()->SetMutable(true); //aGroup->AddPrimitiveArray(myPntArray); + + if (!aReadyToDisplay) + SketcherPrs_Tools::sendEmptyPresentationError(myConstraint, + "An empty AIS presentation: SketcherPrs_LengthDimension"); } @@ -448,8 +452,8 @@ void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace) // ShaperModification:start double aScale = aView->Camera()->Scale(); // Update points coordinate taking the viewer scale into account - if (!updatePoints(MyDist * aScale)) - return; + updateIfReadyToDisplay(MyDist * aScale); + // ShaperModification:end Handle(Graphic3d_Buffer) aAttribs = myPntArray->Attributes(); diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.h b/src/SketcherPrs/SketcherPrs_SymbolPrs.h index fb5112927..458f860a7 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.h +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.h @@ -116,7 +116,7 @@ protected: /// Update myPntArray according to presentation positions /// \return true in case of success - virtual bool updatePoints(double theStep) const { return true; } + virtual bool updateIfReadyToDisplay(double theStep) const { return true; } /// Draw a shape into the given presentation scene /// \param theShape the shape to draw diff --git a/src/SketcherPrs/SketcherPrs_Tangent.cpp b/src/SketcherPrs/SketcherPrs_Tangent.cpp index cb86910fc..09fa68109 100644 --- a/src/SketcherPrs/SketcherPrs_Tangent.cpp +++ b/src/SketcherPrs/SketcherPrs_Tangent.cpp @@ -47,7 +47,7 @@ bool SketcherPrs_Tangent::IsReadyToDisplay(ModelAPI_Feature* theConstraint, return aReadyToDisplay; } -bool SketcherPrs_Tangent::updatePoints(double theStep) const +bool SketcherPrs_Tangent::updateIfReadyToDisplay(double theStep) const { if (!IsReadyToDisplay(myConstraint, myPlane)) return false; diff --git a/src/SketcherPrs/SketcherPrs_Tangent.h b/src/SketcherPrs/SketcherPrs_Tangent.h index baed8cf7d..a3cf98bbd 100644 --- a/src/SketcherPrs/SketcherPrs_Tangent.h +++ b/src/SketcherPrs/SketcherPrs_Tangent.h @@ -43,7 +43,7 @@ protected: /// Update myPntArray according to presentation positions /// \return true in case of success - virtual bool updatePoints(double theStep) const; + virtual bool updateIfReadyToDisplay(double theStep) const; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 1bd65d407..ad33dbe9b 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -42,23 +42,37 @@ namespace SketcherPrs_Tools { AttributePtr getAttribute(ModelAPI_Feature* theFeature, const std::string& theAttrName) { - std::shared_ptr aData = theFeature->data(); - std::shared_ptr anAttr = aData->refattr(theAttrName); - return !anAttr->isObject() ? anAttr->attr() : AttributePtr(); + AttributePtr anAttribute; + if (theFeature) { + std::shared_ptr aData = theFeature->data(); + if (aData.get() && aData->isValid()) { /// essential check as it is called in openGl thread + std::shared_ptr anAttr = aData->refattr(theAttrName); + if (!anAttr->isObject()) + anAttribute = anAttr->attr(); + } + } + return anAttribute; } ObjectPtr getResult(ModelAPI_Feature* theFeature, const std::string& theAttrName) { - std::shared_ptr aData = theFeature->data(); - std::shared_ptr anAttr = aData->refattr(theAttrName); - return anAttr->object(); + ObjectPtr anObject; + if (theFeature) { + std::shared_ptr aData = theFeature->data(); + if (aData.get() && aData->isValid()) { /// essential check as it is called in openGl thread + std::shared_ptr anAttr = aData->refattr(theAttrName); + if (anAttr.get()) + anObject = anAttr->object(); + } + } + return anObject; } std::shared_ptr getShape(ObjectPtr theObject) { ResultConstructionPtr aRes = std::dynamic_pointer_cast(theObject); - if (aRes.get() != NULL) { + if (aRes.get() != NULL && aRes->data()->isValid()) {/// essential check as it is called in openGl thread return aRes->shape(); } return std::shared_ptr(); @@ -70,7 +84,8 @@ std::shared_ptr getPoint(ModelAPI_Feature* theFeature, { std::shared_ptr aPointAttr; - if (!theFeature->data()) + /// essential check as it is called in openGl thread + if (!theFeature || !theFeature->data().get() || !theFeature->data()->isValid()) return std::shared_ptr(); FeaturePtr aFeature; @@ -144,7 +159,7 @@ std::shared_ptr getFeaturePoint(DataPtr theData, { std::shared_ptr aPointAttr; - if (!theData) + if (!theData.get() || !theData->isValid()) /// essential check as it is called in openGl thread return aPointAttr; FeaturePtr aFeature; @@ -184,7 +199,7 @@ FeaturePtr getFeatureLine(DataPtr theData, const std::string& theAttribute) { FeaturePtr aLine; - if (!theData) + if (!theData.get() || !theData->isValid()) /// essential check as it is called in openGl thread) return aLine; std::shared_ptr anAttr = @@ -203,6 +218,9 @@ std::shared_ptr getProjectionPoint(const FeaturePtr theLine, const std::shared_ptr& thePoint) { DataPtr aData = theLine->data(); + if (!aData.get() || !aData->isValid()) + return std::shared_ptr(); + std::shared_ptr aPoint1 = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Line::START_ID())); std::shared_ptr aPoint2 = std::dynamic_pointer_cast( diff --git a/src/SketcherPrs/SketcherPrs_Transformation.cpp b/src/SketcherPrs/SketcherPrs_Transformation.cpp index d9dc0ab7f..e4a4899ff 100644 --- a/src/SketcherPrs/SketcherPrs_Transformation.cpp +++ b/src/SketcherPrs/SketcherPrs_Transformation.cpp @@ -69,7 +69,7 @@ bool SketcherPrs_Transformation::IsReadyToDisplay(ModelAPI_Feature* theConstrain return aReadyToDisplay; } -bool SketcherPrs_Transformation::updatePoints(double theStep) const +bool SketcherPrs_Transformation::updateIfReadyToDisplay(double theStep) const { if (!IsReadyToDisplay(myConstraint, myPlane)) return false; diff --git a/src/SketcherPrs/SketcherPrs_Transformation.h b/src/SketcherPrs/SketcherPrs_Transformation.h index a41c9a0e0..068ac7c09 100644 --- a/src/SketcherPrs/SketcherPrs_Transformation.h +++ b/src/SketcherPrs/SketcherPrs_Transformation.h @@ -47,7 +47,7 @@ protected: /// Update myPntArray according to presentation positions /// \return true in case of success - virtual bool updatePoints(double theStep) const; + virtual bool updateIfReadyToDisplay(double theStep) const; private: bool myIsTranslation; -- 2.39.2