Clear Filters
Clear Filters

MATLAB crashes while re-running compiled mex file.

2 views (last 30 days)
I have a cpp file which gets compiled successfully in Matlab and gives right results. But if I recall the function again, then Matlab crashes. There is no issue if I recompile it again and then run. I assume it is due to some error as mentioned in this post . Why does it work if I recompile it each time and does not work (Matlab crashes) in case of recalling the function in a loop? - How to get hold of the error?
  3 Comments
Michael Mathew
Michael Mathew on 28 May 2016
Edited: Walter Roberson on 31 May 2016
My file is myNewFile.cpp; It compiles to give myNewFile.mexa64. It takes in one argument which is a vector. The following code works fine.
function myNewFileCtrl()
mex -I../../include myNewFile.cpp -L/../../bin -lmylibr1.so -lmylibr2.so
qu = randn(1,6);
J = myNewFile(qu);
end
But this crashes with no warning no error messages.
function myNewFileCtrl()
mex -I../../include myNewFile.cpp -L/../../bin -lmylibr1.so -lmylibr2.so
for i = 1:10
qu = randn(1,6);
J = myNewFile(qu);
end
end
# This is my crash dump file:
# Abnormal termination:
# std::terminate()
#
# Register State (captured):
# RAX = b94c170400000020 RBX = 00007f77b342b7e8
# RCX = 0000000000000002 RDX = 00007f77b341bc20
# RSP = 00007f771fceca20 RBP = 00007f771fcecde0
# RSI = 00007f77b31d23b8 RDI = 00007f771fceca30
#
# R8 = 0000000000000000 R9 = 00007f77b7e49ec0
# R10 = 00007f77b71c987e R11 = 00007f77b71c987f
# R12 = 00007f77b343b878 R13 = 00007f771fcedaa0
# R14 = 00007f771fceda80 R15 = 00007f771fcede60
#
# RIP = 00007f77b313f59e EFL = 0000000000000002
#
# CS = 0001 FS = 0000 GS = 0000
#
# Stack Trace (captured):
# [ 0] 0x00007f77b313f59e /usr/local/MATLAB/R2009b/bin/glnxa64/libmwfl.so+01082782 _ZN2fl4diag5linux6x86_6412context_base12capture_dataEv+00000030
# [ 1] 0x00007f77b313be0a /usr/local/MATLAB/R2009b/bin/glnxa64/libmwfl.so+01068554
# [ 2] 0x00007f77a6af61e5 /usr/local/MATLAB/R2009b/bin/glnxa64/libmwmcr.so+00913893
# [ 3] 0x00007f77a6af7fa0 /usr/local/MATLAB/R2009b/bin/glnxa64/libmwmcr.so+00921504
# [ 4] 0x00007f77a6af8088 /usr/local/MATLAB/R2009b/bin/glnxa64/libmwmcr.so+00921736
# [ 5] 0x00007f77a6af8453 /usr/local/MATLAB/R2009b/bin/glnxa64/libmwmcr.so+00922707
# [ 6] 0x00007f77a6af84c3 /usr/local/MATLAB/R2009b/bin/glnxa64/libmwmcr.so+00922819
# [ 7] 0x00007f77b7baba76 /usr/lib/x86_64-linux-gnu/libstdc++.so.6+00432758
# [ 8] 0x00007f77b7babac1 /usr/lib/x86_64-linux-gnu/libstdc++.so.6+00432833
# [ 9] 0x00007f77b7babcd8 /usr/lib/x86_64-linux-gnu/libstdc++.so.6+00433368
# [ 10] 0x00007f77b92f2ad8 /usr/local/MATLAB/R2009b/bin/glnxa64/libmwi18n.so+00482008 _ZN5boost15throw_exceptionINS_10lock_errorEEEvRKT_+00000136
# [ 11] 0x00007f77972d94fb /usr/local/MATLAB/R2009b/bin/glnxa64/libmwjmi.so+01299707 _ZN3jmi13safeFindClassEP7JNIEnv_RP8_jobjectPKc+00000283
# [ 12] 0x00007f77972d99aa /usr/local/MATLAB/R2009b/bin/glnxa64/libmwjmi.so+01300906 _ZN3jmi13safeFindClassEP7JNIEnv_RSt3setIPNS_8ConsInfoESt4lessIS4_ESaIS4_EERS3_+00000042
# [ 13] 0x00007f7748821145 /usr/local/MATLAB/R2009b/bin/glnxa64/libnativesettings.so+00500037 _ZN14nativesettings24throwJavaExceptionHelperEP7JNIEnv_RN3jmi8ConsInfoEPKc+00000037
# [ 14] 0x00007f77488213cd /usr/local/MATLAB/R2009b/bin/glnxa64/libnativesettings.so+00500685 _ZN14nativesettings31throwJavaExceptionMessageHelperEP7JNIEnv_PKcS3_SsRN3jmi8ConsInfoE+00000141
# [ 15] 0x00007f774882255f /usr/local/MATLAB/R2009b/bin/glnxa64/libnativesettings.so+00505183 _ZN14nativesettings15handleExceptionEP7JNIEnv_P13_jobjectArrayP8_jstringb+00000207
# [ 16] 0x00007f7748825bd1 /usr/local/MATLAB/R2009b/bin/glnxa64/libnativesettings.so+00519121 _ZN14nativesettings9nativeGetEP7JNIEnv_P7_jclasslP13_jobjectArrayP8_jstringS7_+00000609
# [ 17] 0x00007f7782797d98 <unknown-module>+00000000
# [ 18] 0x00007f778278b233 <unknown-module>+00000000
# [ 19] 0x00007f778278b233 <unknown-module>+00000000
# [ 20] 0x00007f778278b233 <unknown-module>+00000000
# [ 21] 0x00007f778278b058 <unknown-module>+00000000
# [ 22] 0x00007f778278b233 <unknown-module>+00000000
# [ 23] 0x00007f778278b233 <unknown-module>+00000000
# [ 24] 0x00007f778278b350 <unknown-module>+00000000
# [ 25] 0x00007f778278b058 <unknown-module>+00000000
# [ 26] 0x00007f778278b058 <unknown-module>+00000000
# [ 27] 0x00007f778278b058 <unknown-module>+00000000
# [ 28] 0x00007f778278b058 <unknown-module>+00000000
# [ 29] 0x00007f778278b058 <unknown-module>+00000000
# [ 30] 0x00007f778278b233 <unknown-module>+00000000
# [ 31] 0x00007f778278b058 <unknown-module>+00000000
# [ 32] 0x00007f778278b706 <unknown-module>+00000000
# [ 33] 0x00007f778278b058 <unknown-module>+00000000
# [ 34] 0x00007f778278b706 <unknown-module>+00000000
# [ 35] 0x00007f778278b058 <unknown-module>+00000000
# [ 36] 0x00007f7782e7fc44 <unknown-module>+00000000
James Tursa
James Tursa on 31 May 2016
This is usually the result of a memory access violation caused by a coding error, but we would need to see your code. The reason it may work the first time but not subsequent times is that the first time corrupts memory but doesn't access the corrupted memory until the second time. Recompiling may clear out the corrupted memory before it gets accessed.

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!