Why does MATLAB crash resulting in a stack trace with "mexRunMexFile"?

15 views (last 30 days)
When I run my program, MATLAB crashes with the following stack trace:
Stack Trace (from fault): 
[ 0] 00000000771dc4a5 MSVCR100.dll+00246949 ( strcpy+000085 ) 
[ 1] 000007feeaee775c calc_auto.mexw64+00030556 ( mdlOutputs+003148 )
[ 2] 000007feeaee680c calc_auto.mexw64+00026636 ( mexFunction+003100 )
[ 3] 00000000592b0f83 libmex.dll+00069507 ( mexRunMexFile+000131 ) 
[ 4] 00000000592afce2 libmex.dll+00064738 ( inSwapMexfileReader+000226 ) 
[ 5] 0000000074e8c80d m_dispatcher.dll+00051213 ( Mfh_file::dispatch_fh+000509 ) 
[ 6] 0000000074ee5e8b m_dispatcher.dll+00417419 ( mdAcquireMatlabFunction+002507 ) 
...
The same program used to work in a previous release of MATLAB.  Is this a bug in the new release causing MATLAB to crash?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 2 Feb 2021
Edited: MathWorks Support Team on 5 Feb 2021
The cause of the crash is an error inside the MEX file MATLAB is using.  It is possible the MEX file is not compatible with the newer version of MATLAB.  
When MATLAB utilizes a MEX file, it depends on the implementation of the MEX code for correctness and error handling.  When an unhandled error is encountered inside the MEX file, for example an access violation, MATLAB is not able to handle the exception and the result is a crash.  In order to identify the cause of the crash, being able to understand a stack trace is vital.
For the above crash, the stack trace can be read from bottom to top as follows:
Module 6: MATLAB Dispatcher acquires the MATLAB function being executed
Module 5: MATLAB Dispatches executes the MATLAB function
Module 4: MATLAB is preparing to use the MEX file
Module 3: MATLAB is using the MEX file
Module 2: The custom MEX file is being executed
Module 1: The custom MEX file outputs are being created
Module 0: The program has crashed, and the operating system is trying to handle the crash
As it can be seen from the above description, the crash is occurring inside the MEX file "calc_auto.mexw64".  Module [3], called "mexRunMexFile" is a MathWorks file MATLAB employs to utilize module [1], called "mdlOutputs", inside the user-defined MEX file "calc_auto.mexw64".  This indicates that the most-likely cause of the crash can be found inside the user-defined MEX file "calc_auto.mexw64".  
For help when experiencing a crash due to a MEX file, there are three possible courses of action that may apply:
A) MathWorks MEX file:
If the "mexRunMexFile" module is calling a MathWorks provided MEX file when MATLAB crashes, please contact MathWorks Technical Support for further help via
as the cause of the crash is likely to be a bug in a MathWorks product.  To identify if the MEX file is part of a MathWorks product, look at the location of the MEX file.  From the stack trace, module [1] shows:
[ 1] 000007feeaee775c calc_auto.mexw64+00030556 
Performing a search on the offending MEX file as follows:
>> which -all calc_auto.mexw64
would return the location of the MEX file.  If the location is inside the MATLAB installation, most likely the MEX file is part of a MathWorks product.  The location of the MATLAB installation can be identify by executing the following command inside MATLAB:
>> matlabroot
If the location of the offending MEX file is outside the MATLAB installation, the file is a user-defined MEX file.  
B) Author of User-Defined MEX file:
If the "mexRunMexFile" module is calling a user-define MEX file when MATLAB crashes, and you are the creator of the user-defined MEX file, you can refer to the following documentation page for help in troubleshooting your MEX file:
http://www.mathworks.com/help/matlab/troubleshoot-mex-files-1.html
You can also reach out to MathWorks Technical Support for further help.
C) Non-Author of User-Defined MEX file:
If the "mexRunMexFile" module is calling a user-define MEX file you did not create, please contact the author of the MEX file.  The author of the MEX file is the only person knowledgeable enough and capable to debug the error inside the MEX file.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!