MATLAB Answers

A problem in running a MEX file in a consistent way

3 views (last 30 days)
AP
AP on 25 Jun 2014
Commented: James Tursa on 27 Jun 2014
I have written a MEX file. This file compiles successfully with no problem. For some reasons, which I am really baffled, this MEX file does not work properly any more. Nothing has changed. I am using the same MEX code and the same arguments for executing the MEX file. But it fails. I uninstalled and reinstalled MATLAB but it did not help.
I tracked the problem and it seems when it reaches mexCallMATLAB, it causes a crash.
mxArray *x_locations = ( cellCentered ) ? mxCreateDoubleMatrix( 1, NZ-1, mxREAL ) : mxCreateDoubleMatrix( 1, NZ, mxREAL );
mxArray *y_locations = ( cellCentered ) ? mxCreateDoubleMatrix( 1, NY-1, mxREAL ) : mxCreateDoubleMatrix( 1, NY, mxREAL );
mxArray *z_locations = ( cellCentered ) ? mxCreateDoubleMatrix( 1, NX-1, mxREAL ) : mxCreateDoubleMatrix( 1, NX, mxREAL );
// A loop for filling the values for x_locations, y_locations, z_locations
// ...
// End of the loop
// Create a meshgrid based on the values stored in x_locations, y_locations, z_locations
mxArray *IN[3];
mxArray *OUT[3];
IN[0] = x_locations;
IN[1] = y_locations;
IN[2] = z_locations;
mexPrintf("Line Before mexCallMATLAB\n");
mexCallMATLAB(3, OUT, 3, IN, "meshgrid");
mexPrintf("Line After mexCallMATLAB\n");
When I run the MEX file, only Line Before mexCallMATLAB is printed and the code does not reach to print Line After mexCallMATLAB. Here is the log.
MATLAB crash file:C:\Users\A\AppData\Local\Temp\matlab_crash_dump.7712-1:
------------------------------------------------------------------------
Segmentation violation detected at Wed Jun 25 15:51:21 2014
------------------------------------------------------------------------
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) 64-Bit Server VM mixed mode
Window System : Version 6.1 (Build 7601: Service Pack 1)
Fault Count: 1
Abnormal termination:
Segmentation violation
Register State (from fault):
RAX = 0000000060de7cc0 RBX = 000009a28967bdb0
RCX = 000000ffffffffff RDX = 0000000060ea08e0
RSP = 0000000004106360 RBP = 0000000000000000
RSI = 0000000006fa0000 RDI = 0000000060ea08f0
R8 = 0000000060ea08f0 R9 = 32525c4501cd000a
R10 = 00000000166f3660 R11 = 00000000740faf60
R12 = 0000000004106610 R13 = 00000000041064e0
R14 = 00000000002dc6c0 R15 = 0000000000000000
RIP = 0000000076d33290 EFL = 00010202
CS = 0033 FS = 0053 GS = 002b
Stack Trace (from fault):
[ 0] 0x0000000076d33290 C:\Windows\SYSTEM32\ntdll.dll+00340624 ( RtlFreeHeap+000208 )
[ 1] 0x0000000076be1a4a C:\Windows\system32\kernel32.dll+00137802 ( HeapFree+000010 )
[ 2] 0x00000000725acabc C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251\MSVCR90.dll+00314044 ( free+000028 )
[ 3] 0x0000000075a23075 C:\Program Files\MATLAB\R2012b\bin\win64\libmx.dll+00012405 ( mxFree+000037 )
[ 4] 0x0000000075a84b9d C:\Program Files\MATLAB\R2012b\bin\win64\libmx.dll+00412573 ( mxSubscriptedReference+000621 )
[ 5] 0x000007fee4475709 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00087817 ( inIs_ws_variable+000329 )
[ 6] 0x000007fee44c8cce C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00429262 ( inFunctionHandleInterface::DestroyWorkspace+241806 )
[ 7] 0x000007fee44d2978 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00469368 ( inFunctionHandleInterface::DestroyWorkspace+281912 )
[ 8] 0x000007fee44d5a8b C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00481931 ( inFunctionHandleInterface::DestroyWorkspace+294475 )
[ 9] 0x000007fee44bde1f C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00384543 ( inFunctionHandleInterface::DestroyWorkspace+197087 )
[ 10] 0x000007fee44bdd80 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00384384 ( inFunctionHandleInterface::DestroyWorkspace+196928 )
[ 11] 0x000007fee44e197d C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00530813 ( inFunctionHandleInterface::DestroyWorkspace+343357 )
[ 12] 0x000007fee44e0271 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00524913 ( inFunctionHandleInterface::DestroyWorkspace+337457 )
[ 13] 0x000007fee44c20e9 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00401641 ( inFunctionHandleInterface::DestroyWorkspace+214185 )
[ 14] 0x0000000074e8c80d C:\Program Files\MATLAB\R2012b\bin\win64\m_dispatcher.dll+00051213 ( Mfh_file::dispatch_fh+000509 )
[ 15] 0x0000000074e8d0d6 C:\Program Files\MATLAB\R2012b\bin\win64\m_dispatcher.dll+00053462 ( Mfunction_handle::dispatch+000854 )
[ 16] 0x000007fee4482cd8 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00142552 ( MathWorks::MException::MExceptionEnvelope::MExceptionEnvelope+003336 )
[ 17] 0x000007fee453beb2 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00900786 ( inMexCallMATLAB+000738 )
[ 18] 0x000007fee453bb9e C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00899998 ( IInterpreter::GetInterpreterBridge+148286 )
[ 19] 0x000007fee453bcaf C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00900271 ( inMexCallMATLAB+000223 )
[ 20] 0x0000000061ce6989 C:\Program Files\MATLAB\R2012b\bin\win64\libmex.dll+00027017 ( mexCallMATLAB+000073 )
[ 21] 0x0000000009b02272 D:\Files\mymexfile.mexw64+00008818 ( mexFunction+004722 )
[ 22] 0x0000000061cf0f83 C:\Program Files\MATLAB\R2012b\bin\win64\libmex.dll+00069507 ( mexRunMexFile+000131 )
[ 23] 0x0000000061cefce2 C:\Program Files\MATLAB\R2012b\bin\win64\libmex.dll+00064738 ( inSwapMexfileReader+000226 )
[ 24] 0x0000000061cefe64 C:\Program Files\MATLAB\R2012b\bin\win64\libmex.dll+00065124 ( inSwapMexfileReader+000612 )
[ 25] 0x0000000074e8c80d C:\Program Files\MATLAB\R2012b\bin\win64\m_dispatcher.dll+00051213 ( Mfh_file::dispatch_fh+000509 )
[ 26] 0x0000000074e8d0d6 C:\Program Files\MATLAB\R2012b\bin\win64\m_dispatcher.dll+00053462 ( Mfunction_handle::dispatch+000854 )
[ 27] 0x000007fee44b210b C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00336139 ( inFunctionHandleInterface::DestroyWorkspace+148683 )
[ 28] 0x000007fee44c3edf C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00409311 ( inFunctionHandleInterface::DestroyWorkspace+221855 )
[ 29] 0x000007fee44e0ae8 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00527080 ( inFunctionHandleInterface::DestroyWorkspace+339624 )
[ 30] 0x000007fee44c8d94 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00429460 ( inFunctionHandleInterface::DestroyWorkspace+242004 )
[ 31] 0x000007fee44d2978 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00469368 ( inFunctionHandleInterface::DestroyWorkspace+281912 )
[ 32] 0x000007fee44e18c1 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00530625 ( inFunctionHandleInterface::DestroyWorkspace+343169 )
[ 33] 0x000007fee44e0271 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00524913 ( inFunctionHandleInterface::DestroyWorkspace+337457 )
[ 34] 0x000007fee44c20e9 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00401641 ( inFunctionHandleInterface::DestroyWorkspace+214185 )
[ 35] 0x0000000074e8c80d C:\Program Files\MATLAB\R2012b\bin\win64\m_dispatcher.dll+00051213 ( Mfh_file::dispatch_fh+000509 )
[ 36] 0x0000000074e8d0d6 C:\Program Files\MATLAB\R2012b\bin\win64\m_dispatcher.dll+00053462 ( Mfunction_handle::dispatch+000854 )
[ 37] 0x000007fee45751e5 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+01135077 ( inValidateLoadedObject+001893 )
[ 38] 0x000007fee4584595 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+01197461 ( init_cleaner+015541 )
[ 39] 0x000007fee4587b75 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+01211253 ( inSetMaxFrameCount+002261 )
[ 40] 0x000007fee4587b48 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+01211208 ( inSetMaxFrameCount+002216 )
[ 41] 0x000007fee4587b07 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+01211143 ( inSetMaxFrameCount+002151 )
[ 42] 0x000007fee4470213 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+00066067 ( inPathNotification::function_clear_notification+004019 )
[ 43] 0x000007fee457aed0 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+01158864 ( inEvalCmdWithLocalReturn+000416 )
[ 44] 0x000007fee457ae2c C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+01158700 ( inEvalCmdWithLocalReturn+000252 )
[ 45] 0x000007fee457ad71 C:\Program Files\MATLAB\R2012b\bin\win64\m_interpreter.dll+01158513 ( inEvalCmdWithLocalReturn+000065 )
[ 46] 0x0000000079fbf90d C:\Program Files\MATLAB\R2012b\bin\win64\libmwbridge.dll+00063757 ( mnDebugPrompt+000109 )
[ 47] 0x0000000079fc0471 C:\Program Files\MATLAB\R2012b\bin\win64\libmwbridge.dll+00066673 ( mnParser+000593 )
[ 48] 0x00000000749a64a4 C:\Program Files\MATLAB\R2012b\bin\win64\mcr.dll+00222372 ( mcrInstance::mnParser_on_interpreter_thread+000036 )
[ 49] 0x000000007498681f C:\Program Files\MATLAB\R2012b\bin\win64\mcr.dll+00092191 ( mcr::setInterpreterThreadToCurrent+029887 )
[ 50] 0x0000000074986881 C:\Program Files\MATLAB\R2012b\bin\win64\mcr.dll+00092289 ( mcr::setInterpreterThreadToCurrent+029985 )
[ 51] 0x00000000063fe0b6 C:\Program Files\MATLAB\R2012b\bin\win64\uiw.dll+00385206 ( UIW_IsUserMessage+000086 )
[ 52] 0x00000000063fe7b9 C:\Program Files\MATLAB\R2012b\bin\win64\uiw.dll+00387001 ( UIW_SetGLIMUserMsg+000153 )
[ 53] 0x0000000076ae87fe C:\Windows\system32\USER32.dll+00165886 ( GetMenuBarInfo+000638 )
[ 54] 0x0000000076acf5fb C:\Windows\system32\USER32.dll+00062971 ( SystemParametersInfoW+000235 )
[ 55] 0x0000000076ad4895 C:\Windows\system32\USER32.dll+00084117 ( IsProcessDPIAware+000465 )
[ 56] 0x0000000076d311f5 C:\Windows\SYSTEM32\ntdll.dll+00332277 ( KiUserCallbackDispatcher+000031 )
[ 57] 0x0000000076ad908a C:\Windows\system32\USER32.dll+00102538 ( PeekMessageW+000186 )
[ 58] 0x0000000076ad50fe C:\Windows\system32\USER32.dll+00086270 ( GetKeyState+000238 )
[ 59] 0x0000000076ad3a6f C:\Windows\system32\USER32.dll+00080495 ( PeekMessageA+000087 )
[ 60] 0x00000000063d8f4b C:\Program Files\MATLAB\R2012b\bin\win64\uiw.dll+00233291 ( UIW_SetCurrentDialog+000731 )
[ 61] 0x00000000063ffbe2 C:\Program Files\MATLAB\R2012b\bin\win64\uiw.dll+00392162 ( ws_FreeSystemFont+000546 )
[ 62] 0x000000000485e6a3 C:\Program Files\MATLAB\R2012b\bin\win64\libmwservices.dll+00779939 ( sysq::removeCommitDatabaseUpdatesHook+002131 )
[ 63] 0x000000000485fe18 C:\Program Files\MATLAB\R2012b\bin\win64\libmwservices.dll+00785944 ( sysq::removeCommitDatabaseUpdatesHook+008136 )
[ 64] 0x0000000004861a20 C:\Program Files\MATLAB\R2012b\bin\win64\libmwservices.dll+00793120 ( sysq::addProcessPendingEventsUnitTestHook+000240 )
[ 65] 0x0000000004861ae8 C:\Program Files\MATLAB\R2012b\bin\win64\libmwservices.dll+00793320 ( sysq::addProcessPendingEventsUnitTestHook+000440 )
[ 66] 0x0000000004861ca3 C:\Program Files\MATLAB\R2012b\bin\win64\libmwservices.dll+00793763 ( sysq::addProcessPendingEventsUnitTestHook+000883 )
[ 67] 0x0000000004861d76 C:\Program Files\MATLAB\R2012b\bin\win64\libmwservices.dll+00793974 ( sysq::addProcessPendingEventsUnitTestHook+001094 )
[ 68] 0x000000007498837e C:\Program Files\MATLAB\R2012b\bin\win64\mcr.dll+00099198 ( mcr::setInterpreterThreadToCurrent+036894 )
[ 69] 0x0000000074988665 C:\Program Files\MATLAB\R2012b\bin\win64\mcr.dll+00099941 ( mcr::setInterpreterThreadToCurrent+037637 )
[ 70] 0x000000007497b166 C:\Program Files\MATLAB\R2012b\bin\win64\mcr.dll+00045414 ( DepfunRules::postWarning+003430 )
[ 71] 0x000000013fa48a33 C:\Program Files\MATLAB\R2012b\bin\win64\MATLAB.exe+00035379 ( ???+000000 )
[ 72] 0x000000013fa48c97 C:\Program Files\MATLAB\R2012b\bin\win64\MATLAB.exe+00035991 ( ???+000000 )
[ 73] 0x000000013fa49163 C:\Program Files\MATLAB\R2012b\bin\win64\MATLAB.exe+00037219 ( ???+000000 )
[ 74] 0x0000000076bd59ed C:\Windows\system32\kernel32.dll+00088557 ( BaseThreadInitThunk+000013 )
[ 75] 0x0000000076d0c541 C:\Windows\SYSTEM32\ntdll.dll+00181569 ( RtlUserThreadStart+000033 )
Could someone help on this?

  0 Comments

Sign in to comment.

Answers (1)

James Tursa
James Tursa on 25 Jun 2014
What code is in the loop? Are you sure you are not writing beyond the end of the data memory? What is the code after mexCallMATLAB?

  2 Comments

AP
AP on 26 Jun 2014
The loop is fine. The code works until it wants to execute mexCallMATLAB(3, OUT, 3, IN, "meshgrid"); and then fails and does not print Line After mexCallMATLAB.
James Tursa
James Tursa on 27 Jun 2014
I see nothing obviously wrong with what you have posted, so I am asking to see what you have not posted. What you have posted runs fine on my machine 1000's of times. That is why I suspect it is something you are not telling us or have not posted. So, again, what is the loop actually doing, and what is after the mexCallMATLAB call?

Sign in to comment.

Sign in to answer this question.

Tags


Translated by