Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Threading Crash (AccessViolationException) #489

Open
WalchAndreas opened this issue Jul 10, 2024 · 0 comments
Open

Multi-Threading Crash (AccessViolationException) #489

WalchAndreas opened this issue Jul 10, 2024 · 0 comments

Comments

@WalchAndreas
Copy link

WalchAndreas commented Jul 10, 2024

While loading Ifc-projects, an AccessViolationException is thrown (often), but investigations conclude it is a multi-threading issue.

Assemblies and versions affected:

official nuget-packages:

  • Xbim.Common (6.0.445)
  • Xbim.Essentials (6.0.445)
  • Xbim.Ifc (6.0.445)
  • Xbim.Ifc2x3 (6.0.445)
  • Xbim.Ifc4 (6.0.445)
  • Xbim.Ifc4x3 (6.0.445)
  • Xbim.IO.Esent (6.0.445)
  • Xbim.IO.MemoryModel (6.0.445)
  • Xbim.Tessellator (6.0.445)

local nuget-packages from source (branch feature/netcore)

  • Xbim.Geometry (6.0.0-dev)
  • Xbim.Geometry.Engine.Interop (6.0.0-dev)
  • Xbim.ModelGeometry.Scene (6.0.0-dev)

remote: https://www.myget.org/F/xbim-develop/api/v3/index.json

  • Xbim.Geometry.Abstractions (6.2.346-develop)
    - Xbim.Essentials (>= 6.0.414-develop)

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()

Minimal file to reproduce the issue:

Loading the Minimal Test Project crashes (very often) in a multi threading (standard) environment.

var model = IfcStore.Open(filePath, editor);

// enable caching - we only load once and do not change the project
model.BeginInverseCaching(); 
model.BeginEntityCaching();

if (model.GeometryStore.IsEmpty)
{
    var context = new Xbim3DModelContext(model);
    //upgrade to new geometry representation, uses the default 3D model
    context.CreateContext(null, true, false);
}

Workaround - Single Threading

Enforce single threading by setting Xbim3DModelContext.MaxThreads = 1.

var context = new Xbim3DModelContext(model);
context.MaxThreads = 1; // <--------------------------USE THIS TO ENFORCE SINGLE-THREADING
context.CreateContext(null, true, false);
@WalchAndreas WalchAndreas changed the title Multi-Trheading Crash (AccessViolationException) Multi-Threading Crash (AccessViolationException) Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant