From 2f1373605447e46fccf4081701e21de153eecf11 Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 26 Oct 2018 17:19:39 +0300 Subject: [PATCH] Make TestIntersection work: no crash on remove of PaveFiller before all algorithm is destroyed. --- src/GeomAlgoAPI/GeomAlgoAPI_Intersection.cpp | 24 ++++++++++++-------- src/GeomAlgoAPI/GeomAlgoAPI_Intersection.h | 5 ++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.cpp index 5793dbf0b..49b7fe423 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.cpp @@ -27,10 +27,15 @@ //================================================================================================== GeomAlgoAPI_Intersection::GeomAlgoAPI_Intersection(const ListOfShape& theObjects) + : myFiller(0) { build(theObjects); } +GeomAlgoAPI_Intersection::~GeomAlgoAPI_Intersection() { + if (myFiller) + delete (BOPAlgo_PaveFiller*)myFiller; +} //================================================================================================== void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects) { @@ -53,21 +58,22 @@ void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects) } } - BOPAlgo_PaveFiller aDSFiller; - aDSFiller.SetArguments(anObjects); + BOPAlgo_PaveFiller* aDSFiller = new BOPAlgo_PaveFiller; + myFiller = aDSFiller; + aDSFiller->SetArguments(anObjects); - aDSFiller.SetRunParallel(false); - aDSFiller.SetNonDestructive(false); - aDSFiller.SetGlue(BOPAlgo_GlueOff); + aDSFiller->SetRunParallel(false); + aDSFiller->SetNonDestructive(false); + aDSFiller->SetGlue(BOPAlgo_GlueOff); // optimization for the issue #2399 BOPAlgo_SectionAttribute theSecAttr(Standard_True, Standard_True, Standard_True); - aDSFiller.SetSectionAttribute(theSecAttr); + aDSFiller->SetSectionAttribute(theSecAttr); - aDSFiller.Perform(); - if (aDSFiller.HasErrors()) { + aDSFiller->Perform(); + if (aDSFiller->HasErrors()) { return; } @@ -75,7 +81,7 @@ void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects) anOperation->SetRunParallel(false); anOperation->SetCheckInverted(true); - anOperation->PerformWithFiller(aDSFiller); + anOperation->PerformWithFiller(*aDSFiller); // it references a filler fields, so keep the filler if(anOperation->HasErrors()) { return; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.h b/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.h index 2ea3e0c14..bd0511769 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.h @@ -31,15 +31,20 @@ /// \brief Performs the intersection operations. class GeomAlgoAPI_Intersection : public GeomAlgoAPI_MakeShape { + void* myFiller; ///< store filler to avoid memory leaks public: /// \brief Constructor. /// \param[in] theObjects list of objects. /// \param[in] theTools list of tools. GEOMALGOAPI_EXPORT GeomAlgoAPI_Intersection(const ListOfShape& theObjects); + /// Destructor to erase the filler + GEOMALGOAPI_EXPORT virtual ~GeomAlgoAPI_Intersection(); + private: /// Builds resulting shape. void build(const ListOfShape& theObjects); + }; #endif -- 2.39.2