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

Fixed Null Reference exception, conversion hangs and merged with the main branch #322

Open
wants to merge 29 commits into
base: NetCoreApp31
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e73df8b
Merge pull request #223 from xBimTeam/develop
andyward Oct 9, 2019
402ffcc
Added additional guard to be more tolerant when processing models wit…
andyward Oct 25, 2019
6c98867
More graceful handling of representations without a ContextOfItems. T…
andyward Oct 25, 2019
8c5db8c
Going for green.
andyward Oct 25, 2019
1dae92e
Fixes for SEH and other native code exceptions as well as improved ha…
SteveLockley Mar 27, 2020
477f612
Merge branch 'develop'
SteveLockley Apr 23, 2020
63732e0
Merge branch 'develop'
SteveLockley Apr 23, 2020
52705e3
Merge branch 'develop'
SteveLockley Jun 10, 2020
b3e1320
Update azure-pipelines.yml for Azure Pipelines
martin1cerny Oct 15, 2020
2002e1d
Updated Essentials.
andyward Oct 15, 2020
70cef22
Target net472 - attempt to fix build
andyward Oct 15, 2020
d1c6085
Target net472 - attempt to fix build
andyward Oct 15, 2020
b8152f7
Fixed HintPaths after net472 update
andyward Oct 17, 2020
df298ec
Fixed HintPaths after net472 update
andyward Oct 17, 2020
c39b50b
Build fix: Removed use of deprecated PackageIconUrl in packaging
andyward Oct 18, 2020
e3ef2e7
Update azure-pipelines.yml for Azure Pipelines
andyward Oct 18, 2020
57f9923
Updated the latest Essentials and stubbed implementation of new inter…
andyward Oct 23, 2020
9fb2519
Stubbed out implementation
andyward Oct 26, 2020
67837ce
Updated Essentials
martin1cerny Nov 18, 2020
039e59e
Merge branch 'develop'
SteveLockley Dec 15, 2020
1ec19ba
Merged develop
SteveLockley Dec 15, 2020
02ce514
Merged with Development
SteveLockley Dec 15, 2020
9dd9f04
Stubbed missing interface methods.
CBenghi Mar 3, 2021
c1ba561
Added regression commands for debugging.
CBenghi Mar 3, 2021
4007f28
merged
dmk-rib Mar 29, 2021
6e0f719
Fixed merge issues
dmk-rib Mar 29, 2021
ec86029
Fixed null ref errors
dmk-rib Apr 7, 2021
815a1af
Fixed file hang issues
dmk-rib Apr 7, 2021
9081cb6
Update XbimSolidSet.cpp
dmk-rib Apr 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.8" />
<PackageReference Include="Xbim.Essentials" Version="5.1.313-develop" />
<PackageReference Include="Xbim.Essentials" Version="5.1.328" />
</ItemGroup>
<Choose>
<When Condition="'$(Platform)'=='AnyCPU'">
Expand Down
4 changes: 2 additions & 2 deletions Xbim.Geometry.Engine.Interop/XbimCustomAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private static Assembly ProbeForAssembly(string moduleName)
{
_logger.LogDebug("Getting probing path from executing assembly");
Assembly assembly = Assembly.GetExecutingAssembly(); // The Xbim.Geometry.Engine.Interop assembly
// code base always points to the deployed DLL, which may be different to the executing Location because of Shadow Copying in the AppDomain (e.g. ASP.NET)
var codepath = new Uri(assembly.CodeBase);
// Location always points to the deployed DLL, which may be different to the executing Location because of Shadow Copying in the AppDomain (e.g. ASP.NET)
var codepath = new Uri(assembly.Location);
// Unlike Assembly.Location, CodeBase is a URI [file:\\c:\wwwroot\etc\WebApp\bin\Xbim.Geometry.Engine.Interop.dll]
appDir = Path.GetDirectoryName(codepath.LocalPath);
}
Expand Down
14 changes: 12 additions & 2 deletions Xbim.Geometry.Engine.Interop/XbimGeometryEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public XbimGeometryEngine(ILogger<XbimGeometryEngine> logger)
{
_logger = logger ?? XbimLogging.CreateLogger<XbimGeometryEngine>();

// Warn if runtime for Engine is not present, this is not necessary any more as we are net47

#if DELAY_LOAD

var conventions = new XbimArchitectureConventions(); // understands the process we run under
Expand Down Expand Up @@ -818,6 +816,18 @@ public string ToBrep(IXbimGeometryObject geometryObject)
}
}

public void WriteBrep(string filename, IXbimGeometryObject geomObj)
{
// no logger is provided so no tracing is started for this function
_engine.WriteBrep(filename, geomObj);
}

public IXbimGeometryObject ReadBrep(string filename)
{
// no logger is provided so no tracing is started for this function
return _engine.ReadBrep(filename);
}

public IXbimSolidSet CreateSolidSet(IIfcSweptAreaSolid ifcSolid, ILogger logger = null)
{
using (new Tracer(LogHelper.CurrentFunctionName(), this._logger, ifcSolid))
Expand Down
14 changes: 14 additions & 0 deletions Xbim.Geometry.Engine/XbimGeometryCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,21 @@ namespace Xbim
LoggerExtensions::LogDebug(logger, "GeomEngine: {0} [{1}]", entity->GetType()->Name, msg);
}
}

void XbimGeometryCreator::WriteBrep(System::String^ filename, IXbimGeometryObject^ geomObj)
{
throw gcnew System::NotImplementedException();
// TODO: This is stubbed out until we merge the implementation from unpushed code.
// temp fix for broken build
}

IXbimGeometryObject^ XbimGeometryCreator::ReadBrep(System::String^ filename)
{
throw gcnew System::NotImplementedException();
// TODO: This is stubbed out until we merge the implementation from unpushed code.
// temp fix for broken build
}

void XbimGeometryCreator::LogError(ILogger^ logger, Object^ entity, System::String^ format, ...array<Object^>^ arg)
{
System::String^ msg = System::String::Format(format, arg);
Expand Down
11 changes: 7 additions & 4 deletions Xbim.Geometry.Engine/XbimGeometryCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Xbim
public ref class XbimGeometryCreator : IXbimGeometryEngine
{

static Assembly^ ResolveHandler(Object^ /*Sender*/, System::ResolveEventArgs^ /*args*/)
static Assembly^ ResolveHandler(Object^ /*Sender*/, System::ResolveEventArgs^ /*args*/)
{

// Warning: this should check the args for the assembly name!
Expand Down Expand Up @@ -80,6 +80,9 @@ namespace Xbim
static void LogError(ILogger^ logger, Object^ entity, System::String^ format, ... array<Object^>^ arg);
static void LogDebug(ILogger^ logger, Object^ entity, System::String^ format, ... array<Object^>^ arg);

virtual void WriteBrep(System::String^ filename, IXbimGeometryObject^ geomObj);
virtual IXbimGeometryObject^ ReadBrep(System::String^ filename);

static int BooleanTimeOut;
static double FuzzyFactor;
static double LinearDeflectionInMM;
Expand All @@ -90,7 +93,7 @@ namespace Xbim

virtual XbimShapeGeometry^ CreateShapeGeometry(IXbimGeometryObject^ geometryObject, double precision, double deflection, ILogger^ logger/*, double angle = 0.5, XbimGeometryType storageType = XbimGeometryType::Polyhedron*/)
{
return CreateShapeGeometry(geometryObject, precision, deflection, 0.5, XbimGeometryType::PolyhedronBinary,logger);
return CreateShapeGeometry(geometryObject, precision, deflection, 0.5, XbimGeometryType::PolyhedronBinary, logger);
};

virtual XbimShapeGeometry^ CreateShapeGeometry(double oneMillimetre, IXbimGeometryObject^ geometryObject, double precision, ILogger^ logger)
Expand Down Expand Up @@ -242,9 +245,9 @@ namespace Xbim
{
return Moved(geometryObject, (IIfcPlacement ^)placement);
};
virtual IXbimGeometryObject ^ Moved(IXbimGeometryObject ^geometryObject, IIfcAxis2Placement2D ^placement)
virtual IXbimGeometryObject^ Moved(IXbimGeometryObject^ geometryObject, IIfcAxis2Placement2D^ placement)
{
return Moved(geometryObject, (IIfcPlacement ^)placement);
return Moved(geometryObject, (IIfcPlacement^)placement);
};
virtual IXbimGeometryObject ^ Moved(IXbimGeometryObject ^geometryObject, IIfcObjectPlacement ^objectPlacement, ILogger^ logger);
virtual IXbimGeometryObject^ FromBrep(System::String^ brepStr);
Expand Down
2 changes: 1 addition & 1 deletion Xbim.Geometry.Packages/Xbim.Geometry.Packages.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.8" />
<PackageReference Include="Xbim.Essentials" Version="5.1.313-develop" />
<PackageReference Include="Xbim.Essentials" Version="5.1.328" />
</ItemGroup>

</Project>
78 changes: 75 additions & 3 deletions Xbim.Geometry.Regression/BatchProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using Xbim.Common;
using Xbim.Geometry.Engine.Interop;
using Xbim.Ifc;
using Xbim.Ifc4.Interfaces;
using Xbim.IO.Memory;
Expand Down Expand Up @@ -121,7 +122,6 @@ private ProcessResult ProcessFile(string ifcFile, StreamWriter writer, ILogger<B
var watch = new Stopwatch();
try
{

watch.Start();
using (var model = ParseModelFile(ifcFile, Params.Caching, logger))
{
Expand Down Expand Up @@ -169,11 +169,83 @@ private ProcessResult ProcessFile(string ifcFile, StreamWriter writer, ILogger<B
};

}

// Option to save breps of encountered classes by type or entityLabel for debugging purposes

if (_params.WriteBreps)
{
var path = Path.Combine(
Path.GetDirectoryName(ifcFile),
Path.GetFileName(ifcFile) + ".brep.unclassified");
IXbimGeometryEngine engine = new XbimGeometryEngine();
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
IfcStore s = model as IfcStore;
if (s != null)
{
var ents = new List<IPersistEntity>();

var exportBrepByType = new string[]
{
"IfcFacetedBrep",
// IIfcGeometricRepresentationItem
"IfcCsgSolid",
"IfcExtrudedAreaSolid",
"IfcExtrudedAreaSolidTapered",
"IfcFixedReferenceSweptAreaSolid",
"IfcRevolvedAreaSolid",
"IfcRevolvedAreaSolidTapered",
"IfcSurfaceCurveSweptAreaSolid",
"IfcSectionedSolidHorizontal",
"IfcSweptDiskSolid",
"IfcSweptDiskSolidPolygonal",
"IfcBooleanResult",
"IfcBooleanClippingResult",
// composing objects
"IfcConnectedFaceSet"
};

foreach (var type in exportBrepByType)
{
ents.AddRange(s.Instances.OfType(type, false));
}
foreach (var ent in ents)
{
try
{
Xbim.Common.Geometry.IXbimGeometryObject created = null;
if (ent is IIfcGeometricRepresentationItem igri)
created = engine.Create(igri);
if (ent is IIfcConnectedFaceSet icfs)
created = engine.CreateShell(icfs);
// IIfcConnectedFaceSet
if (created != null)
{
var brep = engine.ToBrep(created);
var brepFileName = Path.Combine(path, $"{ent.EntityLabel}.{ent.GetType().Name}.brep");
using (var tw = File.CreateText(brepFileName))
{
tw.WriteLine("DBRep_DrawableShape");
tw.WriteLine(brep);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error writing brep {ent.EntityLabel}: {ex.Message}");
}
}
}
}

if (_params.Caching)
{
IfcStore s = ((IfcStore)model);
s.SaveAs(xbimFilename, Xbim.IO.StorageType.Xbim);
s.Close();
if (s != null)
{
s.SaveAs(xbimFilename, Xbim.IO.StorageType.Xbim);
s.Close();
}
}
}
}
Expand Down
16 changes: 5 additions & 11 deletions Xbim.Geometry.Regression/Params.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ namespace XbimRegression
/// </summary>
public class Params
{

public int MaxThreads;

private const int DefaultTimeout = 1000 * 60 * 20; // 20 mins
public bool Caching;
public bool WriteBreps = false;
public bool GeometryV1;



public Params(string[] args)
{
if (args.Length < 1)
Expand All @@ -38,7 +36,6 @@ public Params(string[] args)
}

Timeout = DefaultTimeout;

CompoundParameter paramType = CompoundParameter.None;

foreach (string arg in args.Skip(1))
Expand All @@ -51,6 +48,9 @@ public Params(string[] args)
case "/singlethread":
MaxThreads = 1;
break;
case "/writebreps":
WriteBreps = true;
break;
case "/timeout":
paramType = CompoundParameter.Timeout;
break;
Expand All @@ -68,7 +68,6 @@ public Params(string[] args)
break;
}
break;

case CompoundParameter.Timeout:
int timeout;
if (int.TryParse(arg, out timeout))
Expand All @@ -86,16 +85,13 @@ public Params(string[] args)
paramType = CompoundParameter.None;
break;
}

}

IsValid = true;

}

private static void WriteSyntax()
{
Console.WriteLine("Syntax: XbimRegression <modelfolder> [/timeout <seconds>]");
Console.WriteLine("Syntax: XbimRegression <modelfolder> [/timeout <seconds>] [/maxthreads <number>] [/singlethread] /writebreps");
}

/// <summary>
Expand All @@ -122,6 +118,4 @@ private enum CompoundParameter
CachingOn
};
}


}
2 changes: 1 addition & 1 deletion Xbim.Geometry.Regression/XbimRegression.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.8" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NReco.Logging.File" Version="1.0.5" />
<PackageReference Include="Xbim.Essentials" Version="5.1.313-develop" />
<PackageReference Include="Xbim.Essentials" Version="5.1.328" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Xbim.ModelGeometry.Scene\Xbim.ModelGeometry.Scene.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion Xbim.ModelGeometry.Scene/Xbim.ModelGeometry.Scene.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="Xbim.Essentials" Version="5.1.313-develop" />
<PackageReference Include="Xbim.Essentials" Version="5.1.328" />
</ItemGroup>

<Choose>
Expand Down
64 changes: 0 additions & 64 deletions Xbim.ModelGeometry.Scene/Xbim3DModelContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1469,70 +1469,6 @@ private void WriteShapeGeometries(XbimCreateContextHelper contextHelper, ReportP
if (progDelegate != null) progDelegate(101, "WriteShapeGeometries, (" + localTally + " written)");
}

private IXbimGeometryObject CallWithTimeout(IIfcGeometricRepresentationItem shape, ILogger logger, int booleanTimeOutMilliSeconds)
{
Thread threadToKill = null;
Func<IXbimGeometryObject> wrappedAction = () =>
{
threadToKill = Thread.CurrentThread;
try
{
return Engine.Create(shape, logger);
}
catch (ThreadAbortException)
{
_logger.LogWarning("Thread aborted due to timeout");
Thread.ResetAbort();// cancel hard aborting, lets to finish it nicely.
return null;
}

};

IAsyncResult result = wrappedAction.BeginInvoke(null, null);
if (result.AsyncWaitHandle.WaitOne(booleanTimeOutMilliSeconds))
{
var res = wrappedAction.EndInvoke(result);
result.AsyncWaitHandle.Close();
return res;
}
else
{
threadToKill?.Abort();
throw new TimeoutException();
}
}
private IXbimGeometryObjectSet CutWithTimeOut(IXbimGeometryObjectSet elementGeom, IXbimSolidSet cutGeometries, double precision, int booleanTimeOutMilliSeconds)
{
Thread threadToKill = null;
Func<IXbimGeometryObjectSet> wrappedAction = () =>
{
try
{
threadToKill = Thread.CurrentThread;
return elementGeom.Cut(cutGeometries, precision);
}
catch (ThreadAbortException)
{
_logger.LogWarning("Thread aborted due to timeout");
Thread.ResetAbort();// cancel hard aborting, lets to finish it nicely.
return null;
}
};

IAsyncResult result = wrappedAction.BeginInvoke(null, null);
if (result.AsyncWaitHandle.WaitOne(booleanTimeOutMilliSeconds))
{
var res = wrappedAction.EndInvoke(result);
result.AsyncWaitHandle.Close();
return res;
}
else
{
threadToKill?.Abort();
throw new TimeoutException();
}
}

private void WriteRegionsToStore(IIfcRepresentationContext context, IEnumerable<XbimBBoxClusterElement> elementsToCluster, IGeometryStoreInitialiser txn, XbimMatrix3D WorldCoordinateSystem)
{
//set up a world to partition the model
Expand Down
Loading