Matlab R2021b returns exit code -1073740940 or -1073741819 when closing down

14 visualizzazioni (ultimi 30 giorni)
I'm starting to see MATLAB occasionally (or regularly on some workstations) return exit codes -1073740940 and -1073741819.
Some searching of the web suggests that this is really -1073740940 = Code 0xC0000374, STATUS_HEAP_CORRUPTION.
or -1073741819 = Code 0xC0000005, Access Violation error, which occurs when a program tries to access memory that it is not allowed to. This can be caused by various issues such as faulty RAM, corrupted system files, or programming errors like dereferencing null or wild pointers.
What can I do about this, and why is is this happening?
The MATLAB session itself is fine and reports NO errors when anything is running.
The error code ONLY appears as MATLAB is closing down, after everything useful has been done.
I'm this on a few workstations running MATLAB R2021b, with sessions started from a command line, e.g.
start /B /LOW /WAIT C:\"Program Files"\MATLAB\R2021b\bin\matlab.exe -nodesktop -singleCompThread -nosplash -wait -logfile myLogFile.txt -r "myScript.m"
Inside myScript.m is a script that has the following structure:
try
doAllTheBigWork;
MatlabReturnCode = 0; % Sim finished without exception
catch ME
MatlabReturnCode = 1; % Sim finished with exception
disp('Sim stopped with error');
disp(ME);
fprintf('ME.message=%s\n',ME.message)
msgString = getReport(ME, 'extended');
fprintf('%s\n',msgString)
end
exit(MatlabReturnCode)
When the error happens, there is NO visible error in the MATLAB window, and NO error reported to the log file myLogFile.txt. So, we know that myScript.m gets to the line "exit(MatlabReturnCode)" with MatlabReturnCode = 0. However, in the batch file which opens the MATLAB session, the reported error code from the MATLAB process, after it terminates, is occasionally NOT 0, but is instead -1073740940.
This is annoying, because it means that we can't now discriminate between MATLAB sessions that completed successfully or not, with exit codes 0 or 1, because the code is overwritten with -1073740940, even if the MATLAB session was completely successful inside.
[Formatted code for legibility...dpb]

Risposte (1)

dpb
dpb il 22 Apr 2025
I would expect this is only solvable as to the root cause by Mathworks support; one presumes you have run hardware diagnostics on the subject workstations to rule out the memory failures, although I would expect it an unlikely cause given the symptoms appear on more than one system. One might also want to compare the specific systems as for OS updates, etc., against those which don't appear to have the problem to see if there's anything there that might show a commonality like a specific update and/or other isntalled app or particular video board, etc., ... Trying updating drivers for things like videos boards might be another thing to do...
But, to workaround the problem until/unless it can't be resolved, it would appear you could add an express completion code to the log file in the shutdown script that could be read to determine the simulation success/failure--or, create a separate file that would contain only the success code so wouldn't have to parse a long log file...or is only written if fails so success doesn't leave that file around.
But, I'd suggest this is worthy of official support request...oh! Has the Matlab release got all up-to-date patches installed?
  2 Commenti
Andrew Roscoe
Andrew Roscoe il 23 Apr 2025
Fair points. I will be trying this on R2024b soon, when we roll over to it as our standard platform (we are still all using R2021b as standard). I am sort of hoping it might "go away" with R2024b, but if not, I think it could turn into a Mathworks support request.
The 4 workstations in the pool are all server style, Xeon processors or similar. All on WIndows 10. Three have 64 GB RAM, while one has just been upgraded to 128 GB. The error codes have come up so far on two of the 64 GB RAM machines. The MATLAB applications involve quite heavy Simulink simulations, despatched in parallel from a Jenkins server, so there are up to 4 or 6 parallel MATLAB sessions running on each workstation. Each appears to have sufficient RAM, or at least sufficient RAM plus disk swapfile space, to operate. As I say, NO ERRORS are generated during the actual MATLAB sessions, the errors only seem to appear after MATLAB/SImulink has completed all its tasks successfully and is in the process of closing down, and (I assume) releasing all the memory that it used, back to the operating system.
dpb
dpb il 23 Apr 2025
That's probably a fair assessment; unfortunately, I suspect it is a bug in MATLAB and that a fix for R2021b is not happening. "the errors only seem to appear after MATLAB/SImulink has completed all its tasks successfully...". Does that imply that you haven't seen the error in the case of a model failure which might be a klew if so, of just in general MATLAB has completed with/without failure?
I'm sitll on the same OS/MATLAB release here as well, but I haven't run a batch job in ages so wouldn't see such a symptom if it does occur.

Accedi per commentare.

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by