If a structure is used in an anonymous function that is passed to the workspace using the ASSIGNIN function with the 'WS' parameter set to 'caller', the anonymous function results in a segmentation violation. The following code reproduces this issue:
function fooinitVars;temp= @(x) ((CONSTANTS.one / CONSTANTS.two) * x); %This line produces the segmentation violation
endfunction initVarsglobal CONSTANTSCONSTANTS.one=1;CONSTANTS.two=2;assignin('caller','CONSTANTS',CONSTANTS)end
The stack trace of the segmentation violation is below:
Stack Trace: [0] m_interpreter.dll:_inDoesArrayExist(0, 0, 0, 0) + 6 bytes [1] m_interpreter.dll:struct mxArray_tag * __cdecl matrefarg(int)(0, 0, 37, 2623304) + 30 bytes [2] m_interpreter.dll:_inMatRefDispatch(27, 0, 1, 0x0f7f1300) + 498 bytes [3] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *)(1, 35, 3, 0) + 4115 bytes [4] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *)(1, 35, 2, 0) + 272 bytes [5] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0x0f879730, 0, 0, 0x00 <snip>
Best Answer