Skip to content

Commit 0271bb0

Browse files
authored
Merge pull request #533 from xBimTeam/develop
Stability fixes for #526 and #532
2 parents 47c68bb + 1be36e9 commit 0271bb0

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

Xbim.Geometry.Engine/OCC/src/Standard/Standard_OutOfMemory.cxx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,27 @@ void Standard_OutOfMemory::Raise(Standard_SStream& theMessage)
8686
//purpose :
8787
//=======================================================================
8888

89+
// AW Jan 2025: Replaced static instance with dynamically allocated once since this static resource triggers error code C0020001 to be returned
90+
// when the host process exits, due to C's atexit() disposal of managed resources after CLR shutdown. Results in https://github.com/xBimTeam/XbimGeometry/issues/438
91+
// See https://learn.microsoft.com/en-us/archive/blogs/cbrumme/error-c0020001
92+
// There may be better workarounds than this, but given future v6 GE integrates OCC dynamically and don't have the issue a tactical fix will have to do
93+
// This is likely to mean OutOfMemory conditions may not raise an error correctly, at the expense of the majority of cases having a clean exit code.
94+
//
8995
// global instance must be allocated at load-time
90-
static Handle(Standard_OutOfMemory) anOutOfMemInstance = new Standard_OutOfMemory;
96+
//static Handle(Standard_OutOfMemory) anOutOfMemInstance = new Standard_OutOfMemory;
9197

9298
Handle(Standard_OutOfMemory) Standard_OutOfMemory::NewInstance (Standard_CString theMessage)
9399
{
100+
Handle(Standard_OutOfMemory) anOutOfMemInstance = new Standard_OutOfMemory;
101+
94102
anOutOfMemInstance->SetMessageString (theMessage);
95103
return anOutOfMemInstance;
96104
}
97105

98106
Handle(Standard_OutOfMemory) Standard_OutOfMemory::NewInstance (Standard_CString theMessage,
99107
Standard_CString theStackTrace)
100108
{
109+
Handle(Standard_OutOfMemory) anOutOfMemInstance = new Standard_OutOfMemory;
101110
anOutOfMemInstance->SetMessageString (theMessage);
102111
anOutOfMemInstance->SetStackString (theStackTrace);
103112
return anOutOfMemInstance;

Xbim.Geometry.Engine/XbimWire.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,27 @@ namespace Xbim
234234
// todo: this code is not quite robust, it did not manage to close fairly simple polylines.
235235
try
236236
{
237+
const double oneMilli = profile->Model->ModelFactors->OneMilliMeter;
238+
const double modelPrecision = profile->Model->ModelFactors->Precision;
239+
XbimFace^ xbimFace = gcnew XbimFace(loop, true, oneMilli, profile->OuterCurve->EntityLabel, logger);
237240

238-
239-
double oneMilli = profile->Model->ModelFactors->OneMilliMeter;
240-
TopoDS_Face face = gcnew XbimFace(loop, true, oneMilli, profile->OuterCurve->EntityLabel, logger);
241-
ShapeFix_Wire wireFixer(loop, face, profile->Model->ModelFactors->Precision);
242-
wireFixer.ClosedWireMode() = Standard_True;
243-
wireFixer.FixGaps2dMode() = Standard_True;
244-
wireFixer.FixGaps3dMode() = Standard_True;
245-
wireFixer.ModifyGeometryMode() = Standard_True;
246-
wireFixer.SetMinTolerance(profile->Model->ModelFactors->Precision);
247-
wireFixer.SetPrecision(oneMilli);
248-
wireFixer.SetMaxTolerance(oneMilli * 10);
249-
Standard_Boolean closed = wireFixer.Perform();
250-
if (closed)
251-
*pWire = wireFixer.Wire();
252-
else
253-
*pWire = loop;
241+
if (xbimFace->IsValid)
242+
{
243+
TopoDS_Face face = xbimFace;
244+
ShapeFix_Wire wireFixer(loop, face, modelPrecision);
245+
wireFixer.ClosedWireMode() = Standard_True;
246+
wireFixer.FixGaps2dMode() = Standard_True;
247+
wireFixer.FixGaps3dMode() = Standard_True;
248+
wireFixer.ModifyGeometryMode() = Standard_True;
249+
wireFixer.SetMinTolerance(modelPrecision);
250+
wireFixer.SetPrecision(oneMilli);
251+
wireFixer.SetMaxTolerance(oneMilli * 10);
252+
Standard_Boolean closed = wireFixer.Perform();
253+
if (closed)
254+
*pWire = wireFixer.Wire();
255+
else
256+
*pWire = loop;
257+
}
254258
}
255259
catch (Standard_Failure sf)
256260
{

0 commit comments

Comments
 (0)