How do I troubleshoot a MATLAB crash associated with a custom MEX function?

84 views (last 30 days)
While running my code MATLAB crashed and a technical support engineer mentioned the cause may have been a MEX function.  How do I troubleshoot my MATLAB crash?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 24 Jun 2021
Edited: MathWorks Support Team on 24 Jun 2021
In order to troubleshoot your crash, first you need to determine which MEX function caused MATLAB to crash.  Depending on whether you are the author of this MEX function, you have multiple options to troubleshoot the MEX function.
=Determine which MEX function caused MATLAB to crash=
First, you need to obtain the latest crash log from MATLAB.  Refer to the MATLAB Answers post below for information on locating the crash dump file (matlab_crash_dump.XXXX) MATLAB generates:
Once you have the crash log associated with your recent crash, refer to the following MATLAB Answers post to identify the MEX function that caused MATLAB to crash:
=Out-Of-Process Execution of C++ MEX API Based Functions=
If you are using C++ MEX API, you can run your MEX function in a process that is separate from the MATLAB process. Executing the MEX function in a separate process can prevent MATLAB from crashing if the MEX function crashes and can make it easier to troubleshoot MEX functions. Please refer to the following to learn more about Out-of-Process  execution of C++ MEX functions:
Please note that this feature is available only for C++ MEX API based functions and cannot be used with C MEX API based functions.
Please visit the following link to see how to create C++ MEX API based functions:
=Troubleshoot the MEX function=
Once you know which MEX function caused MATLAB to crash, there are two options depending on the authorship of the MEX function.
You are the author of the MEX function:
The documentation has resources for troubleshooting MEX functions.  Please refer to the following documentation pages for more information on debugging MEX functions:
-Introducing MEX functions-
-Troubleshooting MEX functions-
If you are unable to utilize the information in the documentation to troubleshoot your custom MEX function, you can contact Technical Support for help on using the available resources for you to troubleshoot your MEX function.  Note that Technical Support can provide guidance on MEX setup issues, compilers, library dependencies and give general best practices for MEX function creation and debugging only.

More Answers (1)

Anjaneyulu Korapu
Anjaneyulu Korapu on 15 Jan 2021
Edited: Anjaneyulu Korapu on 15 Jan 2021
These instructions did not help me to figureout the issue. I created a case . I need a help from Mathworks team.
Case number : 04692748
  1 Comment
Giuseppe Rocca
Giuseppe Rocca on 20 May 2021
Edited: Giuseppe Rocca on 20 May 2021
I have the same problem (case number 04875854)
In my case its my opinion that the problem arises because the c-function that i've used to create an s-function use an extern reference to another c-file (eg. extern int16 variable). Code generation is ok but if I try to lanch simulation of a referenced model that contains the s-function then Matlab crashes.

Sign in to comment.


Find more on MATLAB Compiler 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!