Matlab crash after calling mex in function or loop

1 view (last 30 days)
Hi,
I have two mex files to interface with a device which work correctly when run in the first time in my code:
startTDC( scan_time)
RawData = readTDC(ROImin,ROImax);
if I select the lines and run them for a second or many times by right clicking they also run correctly.
However if I run them in a section i.e.
startTDC( scan_time)
RawData = readTDC(ROImin,ROImax);
Matlab crashes (see details below). I get the same error calling them in a function.
Can anybody help?
Many thanks,
Chris
R2012b Windows 7
Crash report:
MATLAB crash file:C:\Users\Arrell\AppData\Local\Temp\matlab_crash_dump.6172-1:
------------------------------------------------------------------------
Segmentation violation detected at Thu Sep 22 17:12:50 2016
------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled
Default Encoding: windows-1252
MATLAB Root : C:\Program Files\MATLAB\R2012b
MATLAB Version : 8.0.0.783 (R2012b)
Operating System: Microsoft Windows 7
Processor ID : x86 Family 6 Model 26 Stepping 5, GenuineIntel
Virtual Machine : Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
Window System : Version 6.1 (Build 7601: Service Pack 1)
Fault Count: 1
Abnormal termination:
Segmentation violation
Register State (from fault):
EAX = 00000000 EBX = 1c7f8f0e
ECX = 00000000 EDX = 00040bf8
ESP = 00be7140 EBP = 00be7164
ESI = 00000006 EDI = 00000064
EIP = 671b11f0 EFL = 00010293
CS = 0000001b DS = 00000023 SS = 00000023
ES = 00000023 FS = 0000003b GS = 00000000
Stack Trace (from fault):
[ 0] 0x671b11f0 C:\Users\Arrell\Desktop\SCTDC\testMVS\readTDC.mexw32+00004592 ( mexFunction+000160 )
[ 1] 0x02b5e024 C:\Program Files\MATLAB\R2012b\bin\win32\libmex.dll+00057380 ( mexRunMexFile+000132 )
[ 2] 0x02b5ca79 C:\Program Files\MATLAB\R2012b\bin\win32\libmex.dll+00051833 ( inSwapMexfileReader+000201 )
[ 3] 0x02b5cca3 C:\Program Files\MATLAB\R2012b\bin\win32\libmex.dll+00052387 ( inSwapMexfileReader+000755 )
[ 4] 0x7f638638 C:\Program Files\MATLAB\R2012b\bin\win32\m_dispatcher.dll+00034360 ( Mfh_file::dispatch_fh+000424 )
[ 5] 0x7f638e26 C:\Program Files\MATLAB\R2012b\bin\win32\m_dispatcher.dll+00036390 ( Mfunction_handle::dispatch+000742 )
[ 6] 0x0267a117 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00565527 ( inDestroyWS+333927 )
[ 7] 0x02663dd4 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00474580 ( inDestroyWS+242980 )
[ 8] 0x0264f18b C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00389515 ( inDestroyWS+157915 )
[ 9] 0x02963f83 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+03620739 ( inCallFcnWithTrapInDesiredWS+003361 )
[ 10] 0x02660882 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00460930 ( inDestroyWS+229330 )
[ 11] 0x02658174 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00426356 ( inDestroyWS+194756 )
[ 12] 0x02655743 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00415555 ( inDestroyWS+183955 )
[ 13] 0x0266c1e7 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00508391 ( inDestroyWS+276791 )
[ 14] 0x0266c302 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00508674 ( inDestroyWS+277074 )
[ 15] 0x0264ceec C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00380652 ( inDestroyWS+149052 )
[ 16] 0x0265248d C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00402573 ( inDestroyWS+170973 )
[ 17] 0x0266512d C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00479533 ( inDestroyWS+247933 )
[ 18] 0x7f638638 C:\Program Files\MATLAB\R2012b\bin\win32\m_dispatcher.dll+00034360 ( Mfh_file::dispatch_fh+000424 )
[ 19] 0x7f638e26 C:\Program Files\MATLAB\R2012b\bin\win32\m_dispatcher.dll+00036390 ( Mfunction_handle::dispatch+000742 )
[ 20] 0x026c7f19 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00884505 ( inMainLoopIdle+006825 )
[ 21] 0x026d06ef C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00919279 ( inEvalCmd+000703 )
[ 22] 0x026d53f9 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00939001 ( inSetMaxFrameCount+000665 )
[ 23] 0x026d53d5 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00938965 ( inSetMaxFrameCount+000629 )
[ 24] 0x026d5390 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00938896 ( inSetMaxFrameCount+000560 )
[ 25] 0x026b1fa0 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00794528 ( MathWorks::MException::MExceptionEnvelope::GetErrorMessage+001600 )
[ 26] 0x026cbf60 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00900960 ( inEvalCmdWithLocalReturn+000224 )
[ 27] 0x026cbf09 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00900873 ( inEvalCmdWithLocalReturn+000137 )
[ 28] 0x026cbe9e C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00900766 ( inEvalCmdWithLocalReturn+000030 )
[ 29] 0x026cbed9 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00900825 ( inEvalCmdWithLocalReturn+000089 )
[ 30] 0x026d0357 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00918359 ( inInitInterestRegistry+000407 )
[ 31] 0x026d0381 C:\Program Files\MATLAB\R2012b\bin\win32\m_interpreter.dll+00918401 ( inEvalCmdWithLocalReturnInDesiredWS+000033 )
[ 32] 0x023d8933 C:\Program Files\MATLAB\R2012b\bin\win32\iqm.dll+01149235 ( iqm::InternalEvalPlugin::inEvalCmdWithLocalReturn+000211 )
[ 33] 0x023d759a C:\Program Files\MATLAB\R2012b\bin\win32\iqm.dll+01144218 ( iqm::InternalEvalPlugin::InternalEvalPlugin+002554 )
[ 34] 0x023d8aee C:\Program Files\MATLAB\R2012b\bin\win32\iqm.dll+01149678 ( iqm::InternalEvalPlugin::inEvalCmdWithLocalReturn+000654 )
[ 35] 0x023d92d8 C:\Program Files\MATLAB\R2012b\bin\win32\iqm.dll+01151704 ( iqm::InternalEvalPlugin::execute+000152 )
[ 36] 0x0c305a24 C:\Program Files\MATLAB\R2012b\bin\win32\nativejmi.dll+00219684 ( nativejmi::JmiIIP::serializeExplicit+002308 )
[ 37] 0x0c32edbd C:\Program Files\MATLAB\R2012b\bin\win32\nativejmi.dll+00388541 ( Java_com_mathworks_jmi_Matlab_nativeGetMemOpt+002221 )
[ 38] 0x02328655 C:\Program Files\MATLAB\R2012b\bin\win32\iqm.dll+00427605 ( iqm::IqmQE::qeInstance+024549 )
[ 39] 0x02321b83 C:\Program Files\MATLAB\R2012b\bin\win32\iqm.dll+00400259 ( iqm::BaseIqmPlugin::createEvent+032115 )
[ 40] 0x7e1c9d7d C:\Program Files\MATLAB\R2012b\bin\win32\libmwbridge.dll+00040317 ( ioCmdLineEditSave+004109 )
[ 41] 0x7e1ca190 C:\Program Files\MATLAB\R2012b\bin\win32\libmwbridge.dll+00041360 ( ioReadLine+000096 )
[ 42] 0x7e1caa90 C:\Program Files\MATLAB\R2012b\bin\win32\libmwbridge.dll+00043664 ( ioReadLine+002400 )
[ 43] 0x7e1cdb57 C:\Program Files\MATLAB\R2012b\bin\win32\libmwbridge.dll+00056151 ( QueryMLFcnTable_libmwbridge+000343 )
[ 44] 0x7e1cdc0b C:\Program Files\MATLAB\R2012b\bin\win32\libmwbridge.dll+00056331 ( QueryMLFcnTable_libmwbridge+000523 )
[ 45] 0x7e1ce388 C:\Program Files\MATLAB\R2012b\bin\win32\libmwbridge.dll+00058248 ( mnParser+000488 )
[ 46] 0x7f29dfd3 C:\Program Files\MATLAB\R2012b\bin\win32\mcr.dll+00188371 ( mcrInstance::mnParser_on_interpreter_thread+000051 )
[ 47] 0x7f282af2 C:\Program Files\MATLAB\R2012b\bin\win32\mcr.dll+00076530 ( mcr::setInterpreterThreadToCurrent+021842 )
[ 48] 0x7f283615 C:\Program Files\MATLAB\R2012b\bin\win32\mcr.dll+00079381 ( mcr::setInterpreterThreadToCurrent+024693 )
[ 49] 0x7f283696 C:\Program Files\MATLAB\R2012b\bin\win32\mcr.dll+00079510 ( mcr::setInterpreterThreadToCurrent+024822 )
[ 50] 0x74e0c709 C:\Program Files\MATLAB\R2012b\bin\win32\uiw.dll+00313097 ( UIW_IsUserMessage+000121 )
[ 51] 0x74e0ccd6 C:\Program Files\MATLAB\R2012b\bin\win32\uiw.dll+00314582 ( UIW_SetGLIMUserMsg+000134 )
[ 52] 0x76b16d50 C:\Windows\system32\USER32.dll+00224592 ( SetWindowsHookExA+000116 )
[ 53] 0x76aee179 C:\Windows\system32\USER32.dll+00057721 ( SystemParametersInfoW+000271 )
[ 54] 0x76af2467 C:\Windows\system32\USER32.dll+00074855 ( PtInRect+000253 )
[ 55] 0x77706b2e C:\Windows\SYSTEM32\ntdll.dll+00289582 ( KiUserCallbackDispatcher+000046 )
[ 56] 0x76af2af3 C:\Windows\system32\USER32.dll+00076531 ( GetAncestor+000126 )
[ 57] 0x74dedfdd C:\Program Files\MATLAB\R2012b\bin\win32\uiw.dll+00188381 ( UIW_SetCurrentDialog+000637 )
[ 58] 0x74e0dd0f C:\Program Files\MATLAB\R2012b\bin\win32\uiw.dll+00318735 ( ws_FreeSystemFont+000495 )
[ 59] 0x01f14277 C:\Program Files\MATLAB\R2012b\bin\win32\libmwservices.dll+00672375 ( sysq::ws_ppeHook::ws_ppeHook+009991 )
[ 60] 0x01f14c8c C:\Program Files\MATLAB\R2012b\bin\win32\libmwservices.dll+00674956 ( sysq::removeCommitDatabaseUpdatesHook+001388 )
[ 61] 0x01f15d46 C:\Program Files\MATLAB\R2012b\bin\win32\libmwservices.dll+00679238 ( sysq::removeCommitDatabaseUpdatesHook+005670 )
[ 62] 0x01f170b8 C:\Program Files\MATLAB\R2012b\bin\win32\libmwservices.dll+00684216 ( sysq::addProcessPendingEventsUnitTestHook+000296 )
[ 63] 0x01f17258 C:\Program Files\MATLAB\R2012b\bin\win32\libmwservices.dll+00684632 ( sysq::addProcessPendingEventsUnitTestHook+000712 )
[ 64] 0x01f172ca C:\Program Files\MATLAB\R2012b\bin\win32\libmwservices.dll+00684746 ( sysq::addProcessPendingEventsUnitTestHook+000826 )
[ 65] 0x01f17322 C:\Program Files\MATLAB\R2012b\bin\win32\libmwservices.dll+00684834 ( svWS_ProcessPendingEvents+000018 )
[ 66] 0x7f284853 C:\Program Files\MATLAB\R2012b\bin\win32\mcr.dll+00084051 ( mcr::setInterpreterThreadToCurrent+029363 )
[ 67] 0x7f284ae2 C:\Program Files\MATLAB\R2012b\bin\win32\mcr.dll+00084706 ( mcr::setInterpreterThreadToCurrent+030018 )
[ 68] 0x7f279e2f C:\Program Files\MATLAB\R2012b\bin\win32\mcr.dll+00040495 ( DepfunRules::postWarning+003231 )
[ 69] 0x7f27cb26 C:\Program Files\MATLAB\R2012b\bin\win32\mcr.dll+00052006 ( mcr_invoke_on_interpreter_thread+001094 )
[ 70] 0x00397632 C:\Program Files\MATLAB\R2012b\bin\win32\MATLAB.exe+00030258 ( ???+000000 )
[ 71] 0x0039772f C:\Program Files\MATLAB\R2012b\bin\win32\MATLAB.exe+00030511 ( ???+000000 )
[ 72] 0x00397938 C:\Program Files\MATLAB\R2012b\bin\win32\MATLAB.exe+00031032 ( ???+000000 )
[ 73] 0x00397dcd C:\Program Files\MATLAB\R2012b\bin\win32\MATLAB.exe+00032205 ( ???+000000 )
[ 74] 0x773bef1c C:\Windows\system32\kernel32.dll+00323356 ( BaseThreadInitThunk+000018 )
[ 75] 0x77723648 C:\Windows\SYSTEM32\ntdll.dll+00407112 ( RtlInitializeExceptionChain+000239 )
[ 76] 0x7772361b C:\Windows\SYSTEM32\ntdll.dll+00407067 ( RtlInitializeExceptionChain+000194 )
This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.
If this problem is reproducible, please submit a Service Request via:
http://www.mathworks.com/support/contact_us/
A technical support engineer might contact you with further information.
Thank you for your help.
  1 Comment
James Tursa
James Tursa on 22 Sep 2016
Usually this indicates a bug in the mex routine. But we would need to see the source code to have any hope of helping you. Maybe post a small version of your source code that reproduces the error. In general, it is not unusual for mex routines with memory access errors to seem to work the first time and fail on subsequent times (1st call corrupts memory but doesn't access that corrupted memory ... but subsequent calls access the corrupted memory).

Sign in to comment.

Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!