xBimTeam / XbimGeometry

XbimGeometry contains the CLR interop libraries and the c++ engine used to compute the 3D geometry of models.
https://xbimteam.github.io/
Other
256 stars 128 forks source link

AccessViolationException when loading a IFC file #456

Open christianstroh opened 10 months ago

christianstroh commented 10 months ago

When loading a specific IFC file, a AccessViolationException sporadically occurs.

Assemblies and versions affected:

Project Xbim.Geometry.Engine in solution Xbim.Geometry.Engine (master branch)

Steps (or code) to reproduce the issue:

Load a specific ifc file with XbimXplorer.

Minimal file to reproduce the issue:

IFC files need to be zipped to be uploaded. Then just drag & drop here

Expected behavior:

That no crash occurs ;)

Actual behavior or exception details:

System.AccessViolationException The exception that is thrown when there is an attempt to read or write protected memory.

StackTrace: at BRepOffsetAPI_MakePipeShell.{ctor}(BRepOffsetAPI_MakePipeShell , TopoDS_Wire ) at Xbim.Geometry.XbimSolid.BuildSweptDiskSolid(TopoDS_Wire* directrixWire, Double radius, Double innerRadius, BRepBuilderAPI_TransitionMode transitionMode) at Xbim.Geometry.XbimSolid.Init(IIfcSweptDiskSolid solid, ILogger logger) at Xbim.Geometry.XbimSolid..ctor(IIfcSweptDiskSolid solid, ILogger logger) at Xbim.Geometry.XbimGeometryCreator.CreateSolid(IIfcSweptDiskSolid ifcSolid, ILogger logger) at Xbim.Geometry.XbimGeometryCreator.Create(IIfcGeometricRepresentationItem geomRep, IIfcAxis2Placement3D objectLocation, ILogger logger) at Xbim.Geometry.Engine.Interop.XbimGeometryEngine.Create(IIfcGeometricRepresentationItem ifcRepresentation, ILogger logger) in C:\Git\BIM\XbimGeometry\Xbim.Geometry.Engine.Interop\XbimGeometryEngine.cs:line 74

andyward commented 10 months ago

Hi Christian

Which version of Geometry Engine are you using Christian? From source, Myget or Nuget?

These are usually down to edge cases in the data triggering an issue in the OCC layer. Will really need the model (or part of to diagnose. There's a chance it's fixed in latest 5.1 (and maybe a better chance it's in 6.0)

Have you tried the latest 5.1 develop version: https://www.myget.org/feed/xbim-develop/package/nuget/Xbim.Geometry/5.1.730-develop ?

christianstroh commented 10 months ago

Hi Andy

I use Visual Studio's NuGet Package Manager. When I try to install version 5.1.730-develop, this error message appears: Could not install package 'Xbim.Geometry.Engine.Interop 5.1.730-develop'. You are trying to install this package into a project that targets 'native,Version=v0.0', but the package does not contain any assembly references or content files that are compatible with that framework.

I will ask if I am allowed to provide the ifc file.

namkhang2603 commented 3 months ago

I'm getting the same error

andyward commented 3 months ago

@namkhang2603 which error are you seeing? An issue installing 5.1.730-develop - or the original issue (System.AccessViolationException)

andyward commented 3 months ago

I use Visual Studio's NuGet Package Manager. When I try to install version 5.1.730-develop, this error message appears: Could not install package 'Xbim.Geometry.Engine.Interop 5.1.730-develop'. You are trying to install this package into a project that targets 'native,Version=v0.0', but the package does not contain any assembly references or content files that are compatible with that framework.

@christianstroh

Sorry I missed this originally. Assume you've moved passed this now. But sounds like you were trying to load GE into a .net core solution which won't work (unless using the v6/netcore branch)

WalchAndreas commented 3 months ago

Hi, we have also encountered AccessViolationExceptions while loading IFC projects. We locally build nuget packages from source of the v6/netcore branch.

Smaller projects trigger this exception regularly, while for large projects it occurs sporadically.

Stacktrace:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
   at <Module>.BRepBuilderAPI_MakeEdge2d.{ctor}(BRepBuilderAPI_MakeEdge2d*, opencascade.handle<Geom2d_Curve>*)
--------------------------------
   at <Module>.NWireFactory.BuildWire(NWireFactory*, TopoDS_Wire*, NCollection_Sequence<opencascade::handle<Geom2d_BoundedCurve> >*, Double, Double)
   at Xbim.Geometry.Factories.WireFactory.BuildWire(TopoDS_Wire*, Xbim.Ifc4.Interfaces.IIfcIndexedPolyCurve, Boolean)
   at Xbim.Geometry.Factories.WireFactory.BuildWire(TopoDS_Wire*, Xbim.Ifc4.Interfaces.IIfcCurve, Boolean)
   at Xbim.Geometry.Factories.ProfileFactory.BuildProfileWire(TopoDS_Wire*, Xbim.Ifc4.Interfaces.IIfcArbitraryClosedProfileDef)
   at Xbim.Geometry.Factories.ProfileFactory.BuildProfileFace(TopoDS_Face*, Xbim.Ifc4.Interfaces.IIfcArbitraryClosedProfileDef)
   at Xbim.Geometry.Factories.ProfileFactory.BuildProfileFace(TopoDS_Face*, Xbim.Ifc4.Interfaces.IIfcProfileDef)
   at Xbim.Geometry.Factories.SolidFactory.BuildExtrudedAreaSolid(TopoDS_Shape*, Xbim.Ifc4.Interfaces.IIfcExtrudedAreaSolid, Xbim.Ifc4.Interfaces.IIfcProfileDef)
   at Xbim.Geometry.XbimSolid.Init(Xbim.Ifc4.Interfaces.IIfcExtrudedAreaSolid, Xbim.Ifc4.Interfaces.IIfcProfileDef, Microsoft.Extensions.Logging.ILogger)
   at Xbim.Geometry.XbimSolid.Init(Xbim.Ifc4.Interfaces.IIfcSweptAreaSolid, Xbim.Ifc4.Interfaces.IIfcProfileDef, Microsoft.Extensions.Logging.ILogger)
   at Xbim.Geometry.XbimSolid.Init(Xbim.Ifc4.Interfaces.IIfcSolidModel, Microsoft.Extensions.Logging.ILogger)
   at Xbim.Geometry.XbimSolid..ctor(Xbim.Ifc4.Interfaces.IIfcSweptAreaSolid, Microsoft.Extensions.Logging.ILogger, Xbim.Geometry.Services.ModelGeometryService)
   at Xbim.Geometry.XbimGeometryCreator.CreateSolid(Xbim.Ifc4.Interfaces.IIfcExtrudedAreaSolid, Microsoft.Extensions.Logging.ILogger)
   at Xbim.Geometry.XbimGeometryCreator.CreateSolid(Xbim.Ifc4.Interfaces.IIfcSweptAreaSolid, Microsoft.Extensions.Logging.ILogger)
   at Xbim.Geometry.XbimGeometryCreator.Create(Xbim.Ifc4.Interfaces.IIfcGeometricRepresentationItem, Xbim.Ifc4.Interfaces.IIfcAxis2Placement3D, Microsoft.Extensions.Logging.ILogger)
   at Xbim.Geometry.XbimGeometryCreator.Create(Xbim.Ifc4.Interfaces.IIfcGeometricRepresentationItem, Microsoft.Extensions.Logging.ILogger)
   at Xbim.ModelGeometry.Scene.Xbim3DModelContext+<>c__DisplayClass44_0.<WriteShapeGeometries>b__0(Int32)
   at System.Threading.Tasks.Parallel+<>c__DisplayClass43_0`2[[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<PartitionerForEachWorker>b__1(System.Collections.IEnumerator ByRef, Int64, Boolean ByRef)
   at System.Threading.Tasks.TaskReplicator+Replica.Execute()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()

Attached the test-project galerie_test.zip

namkhang2603 commented 3 months ago

@namkhang2603 which error are you seeing? An issue installing 5.1.730-develop - or the original issue (System.AccessViolationException) I using : Xbim.Essentials" Version="6.0.445" Xbim.Geometry" Version="5.1.437" Xbim.IO.Esent" Version="6.0.445" My file is too large to attach, I sent it via the dropbox download link https://www.dropbox.com/scl/fi/h06e7tvjm9jhqmmmijpds/IFC_ERROR.zip?rlkey=psvpswyg04ll5x5ymaa2r923n&st=9xpina88&dl=0 `#Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Repeat 2 times:

at .BRepOffsetAPI_MakePipeShell.{ctor}(BRepOffsetAPI_MakePipeShell, TopoDS_Wire)

at Xbim.Geometry.XbimSolid.BuildSweptDiskSolid(TopoDS_Wire*, Double, Double, BRepBuilderAPI_TransitionMode) at Xbim.Geometry.XbimSolid.Init(Xbim.Ifc4.Interfaces.IIfcSweptDiskSolid, Microsoft.Extensions.Logging.ILogger) at Xbim.Geometry.XbimSolid..ctor(Xbim.Ifc4.Interfaces.IIfcSweptDiskSolid, Microsoft.Extensions.Logging.ILogger) at Xbim.Geometry.XbimGeometryCreator.Create(Xbim.Ifc4.Interfaces.IIfcGeometricRepresentationItem, Xbim.Ifc4.Interfaces.IIfcAxis2Placement3D, Microsoft.Extensions.Logging.ILogger) at Xbim.Geometry.Engine.Interop.XbimGeometryEngine.Create(Xbim.Ifc4.Interfaces.IIfcGeometricRepresentationItem, Microsoft.Extensions.Logging.ILogger) at Xbim.ModelGeometry.Scene.Xbim3DModelContext+<>cDisplayClass39_0.b0(Int32) at System.Threading.Tasks.Parallel+<>cDisplayClass43_0`2[[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].b__1(System.Collections.IEnumerator ByRef, Int64, Boolean ByRef) at System.Threading.Tasks.TaskReplicator+Replica.Execute() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread) at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()`

WalchAndreas commented 2 months ago

Investigations showed that the AccessViolationException in version 6 is caused by multi-threading problems (see Issue #489). Maybe this is also the case for other versions.