Crash during initialization of c++ clib object.
25 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!