Access Violation error after few iterations in a mex file

15 views (last 30 days)
i'm trying to execute a script that calls a mex file, but after 4 correct iterations i get this error:
------------------------------------------------------------------------
Access violation detected at Thu Dec 31 12:36:44 2015
------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled
Crash Mode : continue (default)
Current Graphics Driver: Unknown software
Default Encoding : windows-1252
Graphics card 1 : Intel Corporation ( 0x8086 ) Intel(R) HD Graphics 3000 Version 9.17.10.4229
Host Name : DESKTOP-16B0T2V
MATLAB Architecture : win64
MATLAB Root : C:\Program Files\MATLAB\R2015b
MATLAB Version : 8.6.0.267246 (R2015b)
OpenGL : software
Operating System : Microsoft Windows 10 Pro
Processor ID : x86 Family 6 Model 42 Stepping 7, GenuineIntel
Virtual Machine : Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
Window System : Version 10.0 (Build 10586)
Fault Count: 1
Abnormal termination:
Access violation
Register State (from fault):
RAX = 0000000005e53eb0 RBX = 000000000a3acc48
RCX = 0000000000000001 RDX = 000000000c079fd0
RSP = 00000000045fbb20 RBP = 00000000045fbc20
RSI = 000000000a3b54b8 RDI = 4fdf3b63fffffd80
R8 = 0000000000000001 R9 = 000000000a3acc48
R10 = 000000000c078bb8 R11 = 0000000008ce6318
R12 = 000000000b9a3058 R13 = 000000000916e060
R14 = 000000000a3b54b8 R15 = 0000000000002000
RIP = 0000000005e540ab EFL = 00010206
CS = 0033 FS = 0053 GS = 002b
Stack Trace (from fault):
[ 0] 0x0000000005e540ab C:\Program Files\MATLAB\R2015b\bin\win64\mkl.dll+12927147 XERBLA+08837787
[ 1] 0x0000000005228734 C:\Program Files\MATLAB\R2015b\bin\win64\mkl.dll+00165684 dscal+00000068
[ 2] 0x000000000a393ac3 C:\Users\angel\Desktop\release\lbfgsb\lbfgsb3.0_mex1.2\lbfgsb_wrapper.mexw64+00015043
[ 3] 0x000000000a398ac9 C:\Users\angel\Desktop\release\lbfgsb\lbfgsb3.0_mex1.2\lbfgsb_wrapper.mexw64+00035529
[ 4] 0x000000000a39a011 C:\Users\angel\Desktop\release\lbfgsb\lbfgsb3.0_mex1.2\lbfgsb_wrapper.mexw64+00040977
[ 5] 0x000000000a39adbd C:\Users\angel\Desktop\release\lbfgsb\lbfgsb3.0_mex1.2\lbfgsb_wrapper.mexw64+00044477 mexFunction+00001606
[ 6] 0x00000000fc5f7551 C:\Program Files\MATLAB\R2015b\bin\win64\libmex.dll+00095569 mexRunMexFile+00000129
[ 7] 0x00000000fc5f6872 C:\Program Files\MATLAB\R2015b\bin\win64\libmex.dll+00092274 inSwapMexfileReader+00000594
[ 8] 0x00000000fc5f6426 C:\Program Files\MATLAB\R2015b\bin\win64\libmex.dll+00091174 mexUnlock+00004998
[ 9] 0x0000000014ea4cc3 C:\Program Files\MATLAB\R2015b\bin\win64\m_dispatcher.dll+00019651 Mfh_file::dispatch_fh_impl+00000531
[ 10] 0x0000000014ea488e C:\Program Files\MATLAB\R2015b\bin\win64\m_dispatcher.dll+00018574 Mfh_file::dispatch_fh+00000062
[ 11] 0x0000000014ea51e8 C:\Program Files\MATLAB\R2015b\bin\win64\m_dispatcher.dll+00020968 Mfunction_handle::dispatch+00000968
[ 12] 0x00000000158b7942 C:\Program Files\MATLAB\R2015b\bin\win64\m_lxe.dll+00162114
[ 13] 0x00000000158eab5f C:\Program Files\MATLAB\R2015b\bin\win64\m_lxe.dll+00371551
[ 14] 0x00000000158e9810 C:\Program Files\MATLAB\R2015b\bin\win64\m_lxe.dll+00366608
[ 15] 0x00000000159196e1 C:\Program Files\MATLAB\R2015b\bin\win64\m_lxe.dll+00562913
[ 16] 0x0000000015919406 C:\Program Files\MATLAB\R2015b\bin\win64\m_lxe.dll+00562182
[ 17] 0x000000001597c23f C:\Program Files\MATLAB\R2015b\bin\win64\m_lxe.dll+00967231 MathWorks::lxe::ReleaseCurrentMcrContext+00073359
[ 18] 0x000000001597c146 C:\Program Files\MATLAB\R2015b\bin\win64\m_lxe.dll+00966982 MathWorks::lxe::ReleaseCurrentMcrContext+00073110
[ 19] 0x000000001597bc56 C:\Program Files\MATLAB\R2015b\bin\win64\m_lxe.dll+00965718 MathWorks::lxe::ReleaseCurrentMcrContext+00071846
[ 20] 0x0000000015900b14 C:\Program Files\MATLAB\R2015b\bin\win64\m_lxe.dll+00461588
[ 21] 0x0000000015900adc C:\Program Files\MATLAB\R2015b\bin\win64\m_lxe.dll+00461532
[ 22] 0x000000001590091a C:\Program Files\MATLAB\R2015b\bin\win64\m_lxe.dll+00461082
[ 23] 0x0000000015900802 C:\Program Files\MATLAB\R2015b\bin\win64\m_lxe.dll+00460802
[ 24] 0x00000000150260a1 C:\Program Files\MATLAB\R2015b\bin\win64\m_interpreter.dll+00680097 inEvalCmdWithLocalReturn+00000065
[ 25] 0x00000000fb6029bd C:\Program Files\MATLAB\R2015b\bin\win64\libmwbridge.dll+00076221 mnGetPrompt+00003597
[ 26] 0x00000000fb603597 C:\Program Files\MATLAB\R2015b\bin\win64\libmwbridge.dll+00079255 mnParser+00001079
[ 27] 0x00000000fd0d87a4 C:\Program Files\MATLAB\R2015b\bin\win64\mcr.dll+00362404 mcrInstance::mnParser_on_interpreter_thread+00000036
[ 28] 0x00000000fd0ac477 C:\Program Files\MATLAB\R2015b\bin\win64\mcr.dll+00181367 mcr::runtime::setInterpreterThreadToCurrent+00019751
[ 29] 0x00000000fd0ac4b3 C:\Program Files\MATLAB\R2015b\bin\win64\mcr.dll+00181427 mcr::runtime::setInterpreterThreadToCurrent+00019811
[ 30] 0x00000000fd0accb1 C:\Program Files\MATLAB\R2015b\bin\win64\mcr.dll+00183473 mcr::runtime::setInterpreterThreadToCurrent+00021857
[ 31] 0x00000000fab62aa6 C:\Program Files\MATLAB\R2015b\bin\win64\uiw.dll+00535206 UIW_AttachThreadInput+00001270
[ 32] 0x00000000fab62335 C:\Program Files\MATLAB\R2015b\bin\win64\uiw.dll+00533301 wsd_to_MSW+00004181
[ 33] 0x00000000fab623b9 C:\Program Files\MATLAB\R2015b\bin\win64\uiw.dll+00533433 wsd_to_MSW+00004313
[ 34] 0x00007ff841860b0e C:\WINDOWS\system32\USER32.dll+00199438 CreateWindowStationA+00000846
[ 35] 0x00007ff84184d4ff C:\WINDOWS\system32\USER32.dll+00120063 GetPropW+00000719
[ 36] 0x00007ff84184d466 C:\WINDOWS\system32\USER32.dll+00119910 GetPropW+00000566
[ 37] 0x00007ff843b188a4 C:\WINDOWS\SYSTEM32\ntdll.dll+00690340 KiUserCallbackDispatcher+00000036
[ 38] 0x00007ff841861ed4 C:\WINDOWS\system32\USER32.dll+00204500 Ordinal2559+00000148
[ 39] 0x00007ff84184c7dc C:\WINDOWS\system32\USER32.dll+00116700 PeekMessageW+00000364
[ 40] 0x00007ff84184c640 C:\WINDOWS\system32\USER32.dll+00116288 PeekMessageA+00000256
[ 41] 0x00000000fab0e1cb C:\Program Files\MATLAB\R2015b\bin\win64\uiw.dll+00188875 UIW_ShowMenuItem+00005547
[ 42] 0x00000000fab634c2 C:\Program Files\MATLAB\R2015b\bin\win64\uiw.dll+00537794 UIW_SuspendAttachThreadInput+00000690
[ 43] 0x0000000100160ad3 C:\Program Files\MATLAB\R2015b\bin\win64\libmwservices.dll+01510099 services::system_events::PpeDispatchHook::dispatchOne+00032291
[ 44] 0x000000010016c785 C:\Program Files\MATLAB\R2015b\bin\win64\libmwservices.dll+01558405 sysq::addProcessPendingEventsUnitTestHook+00006101
[ 45] 0x000000010016c830 C:\Program Files\MATLAB\R2015b\bin\win64\libmwservices.dll+01558576 sysq::addProcessPendingEventsUnitTestHook+00006272
[ 46] 0x000000010016e475 C:\Program Files\MATLAB\R2015b\bin\win64\libmwservices.dll+01565813 sysq::getCondition+00004197
[ 47] 0x000000010016fe22 C:\Program Files\MATLAB\R2015b\bin\win64\libmwservices.dll+01572386 svWS_ProcessPendingEvents+00000162
[ 48] 0x00000000fd0ad3cd C:\Program Files\MATLAB\R2015b\bin\win64\mcr.dll+00185293 mcr::runtime::setInterpreterThreadToCurrent+00023677
[ 49] 0x00000000fd0ae03a C:\Program Files\MATLAB\R2015b\bin\win64\mcr.dll+00188474 mcr::runtime::setInterpreterThreadToCurrent+00026858
[ 50] 0x00000000fd0a5c95 C:\Program Files\MATLAB\R2015b\bin\win64\mcr.dll+00154773 mcr_process_events+00007557
[ 51] 0x00000000fd0a75a2 C:\Program Files\MATLAB\R2015b\bin\win64\mcr.dll+00161186 mcr_process_events+00013970
[ 52] 0x0000000011e837ae C:\Program Files\MATLAB\R2015b\bin\win64\MVMLocal.dll+00210862 mvm_server::inproc::LocalFactory::terminate+00081678
[ 53] 0x00000000fa924d99 C:\Program Files\MATLAB\R2015b\bin\win64\mvm.dll+01002905 mvm::detail::initLocalMvmHack+00000537
[ 54] 0x00000000fa925368 C:\Program Files\MATLAB\R2015b\bin\win64\mvm.dll+01004392 mvm::detail::SessionImpl::privateSession+00000376
[ 55] 0x00000000fa9255b2 C:\Program Files\MATLAB\R2015b\bin\win64\mvm.dll+01004978 mvm::detail::SessionImpl::privateSession+00000962
[ 56] 0x0000000140006247 C:\Program Files\MATLAB\R2015b\bin\win64\MATLAB.exe+00025159
[ 57] 0x0000000140007cf4 C:\Program Files\MATLAB\R2015b\bin\win64\MATLAB.exe+00031988
[ 58] 0x00007ff841ce8102 C:\WINDOWS\system32\KERNEL32.DLL+00098562 BaseThreadInitThunk+00000034
[ 59] 0x00007ff843acc2e4 C:\WINDOWS\SYSTEM32\ntdll.dll+00377572 RtlUserThreadStart+00000052
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.** This crash report has been saved to disk as C:\Users\angel\AppData\Local\Temp\matlab_crash_dump.5188-1 **
Caught MathWorks::System::FatalException
[Please exit and restart MATLAB]>>
What could it be and how can i solve the problem?
  3 Comments
Angelo Rubino
Angelo Rubino on 4 Jan 2016
Here you are. I attached the mex routine source code in .txt because i think that it's not short enough to post. Let me know if you find something
James Tursa
James Tursa on 7 Jan 2016
Edited: James Tursa on 7 Jan 2016
Thanks for posting the wrapper. It is not a simple interface so I wasn't able to find anything obvious from a quick once-over. I would probably need to get the source code from the library to compare the interface. Maybe I can try to look at that this weekend. One thing you might try, just to see if it is a simple integer size issue, is to force the Fortran integer type instead of relying on a test. I.e., take this code:
#ifdef _BLAS64_
#define int_F ptrdiff_t
#else
#define int_F int
#endif
and replace it with one or the other type explicitly and try it out. E.g., try this to see if it works:
//#ifdef _BLAS64_
#define int_F ptrdiff_t
//#else
//#define int_F int
//#endif
and if not, then try this:
//#ifdef _BLAS64_
//#define int_F ptrdiff_t
//#else
#define int_F int
//#endif
Maybe that will isolate the problem to the int_F define stuff. If either of the above seems to fix things, then maybe all we need to do is create a smarter test instead of using _ BLAS64 _.

Sign in to comment.

Answers (1)

Rahul Goel
Rahul Goel on 4 Jan 2016
Hi Angelo,
As noted in the segmentation violation crash dump: "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."
Before the community can provide assistance with this issue, you will need to determine where the problem is within your code by debugging it. Most likely, an attempt has been made to write to unallocated memory, or memory is destroyed that is later used by MATLAB.
One debugging technique that may be helpful is to run MATLAB in check_malloc mode. When run in this mode, MATLAB attaches a header and footer to each block of allocated memory. This information can then be used to determine if an attempt is made to write to unallocated memory. Note that, in general, MATLAB will run slower when in check_malloc mode.
For more information on running MATLAB in check_malloc mode, see the Related Solution listed below:
Additionally, be sure to use mxMalloc in your code for any memory that is dynamically created and be sure not to use mxFree on any data returned to MATLAB. See the following URLs for more information on these functions:
Another common error is filling an mxArray in an improper manner. The Related Solution listed below shows four correct methods for filling an mxArray.
Another helpful debugging technique is to include mexPrintf functions periodically in your code. This technique can ultimately be used to determine the line of code that is generating the segmentation violation. By examining the history of pointers used on the offending line, one can determine where they went awry.
For documented MEX debugging tips, see the following External Interfaces documentation URL:
Hope this helps.

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) 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!