Using OpenCascade in a DLL

Hi,

we're writing a module that uses OpenCascade 7.2 in a dynamic loaded DLL.

This module simply reads a STEP or IGES using STEPCAFControl_Reader and IGESCADControl_Reader.

All works but unloading DLL I have an Unhandled exception (Access violation) in

     TKXSBase.dll!StepData_GlobalNodeOfWriterLib::~StepData_GlobalNodeOfWriterLib()    C++
     TKXSBase.dll!StepData_GlobalNodeOfWriterLib::`scalar deleting destructor'(unsigned int)    C++
     TKXSBase.dll!StepData_GlobalNodeOfWriterLib::~StepData_GlobalNodeOfWriterLib()    C++
     TKXSBase.dll!StepData_GlobalNodeOfWriterLib::`scalar deleting destructor'(unsigned int)    C++
     TKXSBase.dll!`dynamic atexit destructor for 'theglobal''()    C++
>    TKXSBase.dll!_CRT_INIT(void * hDllHandle, unsigned long dwReason, void * lpreserved) Line 416    C
     TKXSBase.dll!__DllMainCRTStartup(void * hDllHandle=0x00007ffce46a0000, unsigned long dwReason=0, void * lpreserved=0x00000056e81fea80) Line 522    C

it happens everytime I declare an object STEPCAFControl_Reader or IGESCAFControl_Reader. It happens also if the only code executed by DLL is a declaration like

STEPCAFControl_Reader reader;

Same code in an EXE works fine without problem.

Someone have an Idea?

I attached wizard generated solution (Vs 2012) to test it.

Thank you

Attachments: 
boris.sunik_142083's picture

Hi,

We have exactly the same problem. Any suggestions were appreciated

renato gasoto's picture

Hi,

I too have exactly the same problem. 

One interesting thing I noticed, if I set the order of the libraries on CMakeLists differently, the access violation happens at a different library. Depending on which is loaded first, the error happens either on TKXSBase.dll or TKXDESTEP.dll. Both at StandardHandle::EndScope;

My suspicion is that there is a race condition happening when deleting pointers on shutdown.

Any plan on when this problem will be addressed?

Kirill Gavrilov's picture

Any plan on when this problem will be addressed?

If analysis shows that the problem is within OCCT itself, then as first step it is necessary reporting an issue on Bugtracker (with a reproducer).
And suggestions or patches fixing the issue are welcome, of course.

Giovanni Pennisi's picture

I'm encountering the issue Gabriele De Agostini described, where STEPCAFControl_Reader causes an acces violation during TKXSBase.dll unloading in OCC 7.7.0. It's important to note that this problem wasn't present in OCC version 6.9.0. While I haven't found a solution yet, have you encountered this specific problem with OCC 7.7.0, or are there any known workarounds that might help mitigate it?

Dmitrii Pasukhin's picture

Hello. Hot loading/unloading is still on progress. It is one of the main goals of DE Wrapper implementation. But it will take time. There are no workaround. OCCT DE core has a lot of internal hidden linking and creating a independent entities.

The approximated estimation for starting testing hot unloading is 7.9.

Best regards, Dmitrii.

Giovanni Pennisi's picture

Hello Dmitrii, thank you for the clarification and your quick reply!