- Comment out or remove your S-Function block to determine if your s-function causes the hang.
- If it does, then you could try to use a Vis Studio debugger or gdebug to break in your mdlStart() function to take a look at what is happening. Sounds like a memory corruption issue. https://www.mathworks.com/help/simulink/sfg/debugging-c-mex-s-functions.html
Simulink intermittently hangs after return from mdlStart() in call to external C++ sfunction
2 views (last 30 days)
I'm writing a C++ SFunction for use with Simulink. This SFunciton connects to an exteral code to handle electrical circuit simulation.
In a typical run from Simulink, the following routines are called without any errors being reported by simulink and the C++ SFunctcion works as expecte:
But sometimes after Simulink calls mdlStart() and exits that routine it never calls mdlOutputs() and Simulink doesn't make any simulation progress. It's just stuck at time=0.
I'm not sure how to debug this as it looks like Simulink is not in my code when it hangs. The only way to stop the simulation at this point is to kill the main MATLAB job with "kill -9 <PID>".
Any suggestions on how to debug this?
Mark McBroom on 8 Sep 2021