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
255 stars 128 forks source link

Different exception behaviour between Debug and Release builds #454

Open GVladislavG opened 11 months ago

GVladislavG commented 11 months ago

Hello, xBim team!

I've found very interesting moment. I've changed Exceptions handling a little bit in XbimGeometryCreator.cpp. Strings 304-310.

catch (...)
{
    //throw gcnew Exception(String::Format("General Error Creating {0}, #{1}", geomRep->GetType()->Name, geomRep->EntityLabel));                

    LogError(logger, geomRep, "General Error Creating {0}, #{1}", geomRep->GetType()->Name, geomRep->EntityLabel);
    return XbimGeometryObjectSet::Empty;
} 

Then I built debug version of XBim.Geometry. All my problems with geometry creation have disappeared!)) But if I build release version of the same code, it doesn't work correctly. Also if I move debug-dlls of xBim, that I've built on my computer, to other machine it doesn't work. I use master-branch. It would be greate to fix this problem!

Thanks!

GVladislavG commented 11 months ago

And there are also no Xbim.Geometry.Engine64.pdb and Xbim.Geometry.Engine32.pdb in release build configuration. Release build throws exception in Xbim.Geometry.Engine64.dll while Xbim3DModelContext.CreateContext(). I tried to attach with debugger to learn deeper, but there is no symbol files in release. Debug build doesn't throw any exception and works well.

andyward commented 11 months ago

My C++ is rusty, but some thoughts:

In debug builds there are additional checks on things like stack & heap overruns - likely why it only fails in Release. (In debug I'd check for exceptions being raised and logged. Enable all C++ exceptions in the Exception Settings window).

Equally in Release config the debug symbols (PDBs) are not created - which is why you don't see the symbol files.

Things you can try:

  1. Enable / change Runtime Checks in Debug
image
  1. Change the Generate Debug Info setting in the Linker in Release
image
GVladislavG commented 11 months ago

Is there any way to get the same behavior as debug build in release? Skipping some exceptions and getting result geometry (maby with skiped elements) would be greate result for me now)

andyward commented 11 months ago

Not really, short of using a debug (unoptimised) build. The /RTC (runtime checks) will only work in Debug/Un-optimised builds. https://learn.microsoft.com/en-us/cpp/build/reference/rtc-run-time-error-checks?view=msvc-170

What I'd hope the debug build willlet you do is identify the data / scenario that triggers the crash in Release. If you can track it down to a particular element others may be able to take a look.

GVladislavG commented 11 months ago

So one more question. Why debug-dlls don't work on other machine (without Visual Studio)? Does it also means that I can't move them to other computer?

andyward commented 11 months ago

I think it uses different C++ runtime/libs in DEBUG - and these won't be on machines without VS. Probably a good reason not to go down that route. Best approach is to get a fix for the actual problem - but will need your model (or a subset of it) to reproduce

GVladislavG commented 11 months ago

Ok. There are three problem files in archive. If I use XBim.Essentials ver 5.1.323 + XBim.Geometry ver 5.1.730-develop, it doesn't crash. But result geometry in 3.ifc contains many incorrect results (screenshot below). 3Ifc 1.ifc and 2.ifc are OK. If I use XBim.Essentials ver 6.0.427-develop + XBim.Geometry ver 5.1.730-develop, it crashes.

3.zip ProblemIFCs.zip