1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0029973: Modeling Algorithms - access violation within BRepAlgoAPI_Cut on empty input shape

Boolean Operations algorithm has been improved to handle the cases with empty shapes arguments correctly.
Test cases for the issue.
This commit is contained in:
emv
2018-07-20 15:16:50 +03:00
committed by bugmaster
parent d3578357e3
commit 3dc5809557
6 changed files with 152 additions and 9 deletions

View File

@@ -163,7 +163,7 @@ void BOPAlgo_BOP::CheckData()
// or equal to the MAXIMAL dimension of the TOOLS;
// 4. COMMON: The arguments and tools could have any dimensions.
//
Standard_Integer iDimMin[2], iDimMax[2];
Standard_Integer iDimMin[2] = { 0, 0 }, iDimMax[2] = { 0, 0 };
Standard_Boolean bHasValid[2] = {Standard_False, Standard_False};
//
for (i=0; i<2; ++i) {
@@ -216,8 +216,14 @@ void BOPAlgo_BOP::CheckData()
AddError (new BOPAlgo_AlertBOPNotAllowed);
return;
}
myDims[0] = iDimMin[0];
myDims[1] = iDimMin[1];
}
if (bHasValid[0] || bHasValid[1])
{
// In case of all empty shapes in one of the groups
// this group aquires the dimension of other group
myDims[0] = bHasValid[0] ? iDimMin[0] : iDimMin[1];
myDims[1] = bHasValid[1] ? iDimMin[1] : iDimMin[0];
}
}
//=======================================================================
@@ -265,24 +271,46 @@ Standard_Boolean BOPAlgo_BOP::TreatEmptyShape()
// One of the groups of arguments consists of empty shapes only,
// so we can build the result of operation right away just by
// choosing the list of shapes to add to result, depending on
// the type of the operation
// the type of the operation.
// Although, if the group with valid shapes consists from more
// than just one shape, depending on the operation type we may need
// to split the shapes in this group before adding them into result.
TopTools_ListOfShape *pLResult = NULL;
//
switch (myOperation) {
case BOPAlgo_FUSE:
{
if (aLValidObjs.Extent() + aLValidTools.Extent() > 1)
// The arguments must be split before adding into result
return Standard_False;
// Add not empty shapes into result
pLResult = bHasValidObj ? &aLValidObjs : &aLValidTools;
break;
}
case BOPAlgo_CUT:
{
if (aLValidObjs.Extent() > 1)
// The objects must be split before adding into result
return Standard_False;
// Add objects into result
pLResult = &aLValidObjs;
break;
}
case BOPAlgo_CUT21:
{
if (aLValidTools.Extent() > 1)
// The tools must be split before adding into result
return Standard_False;
// Add tools into result
pLResult = &aLValidTools;
break;
}
case BOPAlgo_COMMON:
// Common will be empty
// Common will always be empty
break;
default:
break;
@@ -408,6 +436,7 @@ void BOPAlgo_BOP::PerformInternal1(const BOPAlgo_PaveFiller& theFiller)
{
Standard_Boolean bDone = TreatEmptyShape();
if (bDone) {
PrepareHistory();
return;
}
}

View File

@@ -99,9 +99,23 @@ public: //! @name History methods
}
//! History Tool
Handle(BRepTools_History) History() const
Handle(BRepTools_History) History()
{
return myFillHistory ? myHistory : NULL;
if (myFillHistory)
{
if (myHistory.IsNull())
// It seems the algorithm has exited with error before filling
// the history. Initialize the History tool to return the empty
// History instead of NULL.
myHistory = new BRepTools_History();
return myHistory;
}
// If the History has not been requested to be filled, return the NULL
// explicitly as the History may be partially filled for the algorithm's
// internal needs.
return NULL;
}
public: //! @name Enabling/Disabling the history collection.