Clear Filters
Clear Filters

matlab crashes when simulink model runs for the second time

11 views (last 30 days)
I run a Simulnik model which contains a s-function, this s-function is implemented in c++ and contains some global variables.
The model runs fine at first, when I stop the model and run it again Matlab crashes unless I use "clear mex".
I guess it may be a memory management problem in the C++ code.
In addition, the mex file corresponding to the s-function also references a dll file.
A part of stack trace is as follows:
Stack Trace (from fault):
[ 0] 0x00007fff61b0eb09 E:\OpenDDS-3.26.1\ACE_wrappers\lib\ACEd.dll+02681609 ACE_Configuration_Win32Registry::enumerate_values+01529406
[ 1] 0x00007ffec567d579 E:\OpenDDS-3.26.1\lib\OpenDDS_Dcpsd.dll+12047737 OpenDDS::DCPS::getMetaStruct<DDS::PublicationMatchedStatus>+04362850
[ 2] 0x00007ffec55d9a75 E:\OpenDDS-3.26.1\lib\OpenDDS_Dcpsd.dll+11377269 OpenDDS::DCPS::getMetaStruct<DDS::PublicationMatchedStatus>+03692382
[ 3] 0x00007fff463c0847 D:\onedrive\AVIC\bus2bus\BusoneDDS_Idld.dll+03475527 OpenDDS::DCPS::DataReaderImpl_T<bustwo::inputs>::purge_data+00000103
[ 4] 0x00007fff462b29c3 D:\onedrive\AVIC\bus2bus\BusoneDDS_Idld.dll+02369987 OpenDDS::DCPS::DataReaderImpl_T<bustwo::inputs>::~DataReaderImpl_T<bustwo::inputs>+00001347
[ 5] 0x00007fff462f77e8 D:\onedrive\AVIC\bus2bus\BusoneDDS_Idld.dll+02652136 OpenDDS::DCPS::DataReaderImpl_T<bustwo::inputs>::`vbase destructor'+00000040
[ 6] 0x00007fff462fe80c D:\onedrive\AVIC\bus2bus\BusoneDDS_Idld.dll+02680844 OpenDDS::DCPS::DataReaderImpl_T<bustwo::inputs>::`scalar deleting destructor'+00000044
[ 7] 0x00007ffec53204e4 E:\OpenDDS-3.26.1\lib\OpenDDS_Dcpsd.dll+08520932 OpenDDS::DCPS::getMetaStruct<DDS::PublicationMatchedStatus>+00836045
[ 8] 0x00007fff4634b473 D:\onedrive\AVIC\bus2bus\BusoneDDS_Idld.dll+02995315 OpenDDS::DCPS::LocalObjectBase::_remove_ref+00000067
[ 9] 0x00007fff49643fc3 E:\OpenDDS-3.26.1\ACE_wrappers\lib\TAOd.dll+02047939 TAO::unbounded_basic_string_sequence<char>::release+01091232
[ 10] 0x00007fff461d8e4d D:\onedrive\AVIC\bus2bus\BusoneDDS_Idld.dll+01478221 CORBA::release<bustwo::inputsDataReader *>+00000077
[ 11] 0x00007fff461e386b D:\onedrive\AVIC\bus2bus\BusoneDDS_Idld.dll+01521771 TAO::Objref_Traits<bustwo::inputsDataReader>::release+00000043
[ 12] 0x00007ff81be05c86 D:\onedrive\AVIC\bus2bus\busoneDDS.mexw64+00023686 mexFunction+00010310
[ 13] 0x00007ff81be033b2 D:\onedrive\AVIC\bus2bus\busoneDDS.mexw64+00013234

Answers (1)

Andreas Goser
Andreas Goser on 16 Apr 2024
I have seen issues like this in a situation where the C/C++ code overwrites sections of memory and causes the crash. It certainly is not easy to debug. Many MATLAB/Simulink users are not at the same time strong in C/C++ and thus need help from colleagues with debugging. Especially if the C/C++ code comes from a third party.

Tags

Community Treasure Hunt

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

Start Hunting!