필터 지우기
필터 지우기

Crash during initialization of c++ clib object.

조회 수: 12 (최근 30일)
Trevor
Trevor 2024년 2월 9일
댓글: Trevor 2024년 2월 27일
Hello All,
I am building a custom visual studio dll and I generate a clib interface to it using the interfaceGeneration routines.
I am using MATLAB 2023a with visual studio 2019.
I have a custom c++ class (called DeviceInfo) that is a inherted class from a simple HardwareInfo class.
Internally (in the cpp) this class checks some shared pointers that the DeviceInfo object owns and free them if nessecary in its destructor. (that are all alocated internally in the cpp) among these are thread objects.
If I build the dll in RelWithDebInfo. I can use visual studio to attach to the matlabclibhost and do some basic debugging. I am getting seg faults sometimes when I create/delete a DeviceInfo object from matlab. I also am getting heap corruption error from the visual studio debugger.
Critical error detected c0000374
A breakpoint instruction (__debugbreak() statement or a similar call) was executed in MATLABCLibHost.exe.
Exception thrown at 0x00007FFFFCF1C7A9 (ntdll.dll) in MATLABCLibHost.exe: 0xC0000374: A heap has been corrupted (parameters: 0x00007FFFFCF938A0).
Unhandled exception at 0x00007FFFFCF1C7A9 (ntdll.dll) in MATLABCLibHost.exe: 0xC0000374: A heap has been corrupted (parameters: 0x00007FFFFCF938A0).
Exception thrown: read access violation.
**_Left** was 0xFFFFFFFFFFFFFFFF.
usage MATLAB code:
testDevice = clib.ImatestControl.ControlAPI.DummyDeviceInfo
testDevice = clib.ImatestControl.ControlAPI.DummyDeviceInfo %<---destructor should be called on the 1st instance here
Any Help/Hints would be appreciated.
Thanks,
Trevor

채택된 답변

Rishi
Rishi 2024년 2월 27일
Hi Trevor,
From your question, I understand that you have created a class called 'DeviceInfo' and are encountering errors when attempting to create or delete an object of that class.
From the stack trace you have provided, it appears that the error you are facing is due to heap corruption. Heap corruption usually occurs when you are trying to write to memory outside its bounds, or when you free memory more than once. Heap corruption is generally not caused by the line of code where it is detected. Check for buffer overruns and other places where you might be deleting memory (or writing to memory; however, based on your question, it seems the former is the issue in your case).
A similar issue can be found below in the 'cplusplus' forum:
Hope this helps!
  댓글 수: 1
Trevor
Trevor 2024년 2월 27일
Hi Rishi,
Thanks for the reply. Turns out this issue was because the headers I was using for clib generation were different than what the dll library was built with (I was restricting some member variables/functions from being parsed by the generation which I am guessing essentially made the data structure sizes mismatch during runtime. - causing heap errors) If I use the headers as they are used to build the dll - things seem to be stable.
Thanks,
-Trevor

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by