Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

c++ - Preventing a MEX file from crashing in MATLAB

I have a MEX file which I "borrowed" from someone else to help me code a semi-automated nuclear detection algorithm. The problem is that the MEX file sporadically causes a segmentation fault. However, if the code is run with the same parameters a second time, it's fine.

I was hoping there was a sort of try/catch idiom for MEX files, but after spending most of my Saturday looking for something, I couldn't find anything.

Any help on this issue would be amazing! Otherwise, I am going to have to port the .cpp into MATLAB (and it's around 10,000 lines using hundreds of dependencies :-().

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Which platform are you using? There are methods to help debug your MEX files. Whenever there is a segmentation fault, you can use an IDE to tell you where in the code it's crashing.

Here are the directions for Mac OS: http://www.mathworks.com/help/matlab/matlab_external/debugging-on-mac-platforms.html

Here are the directions for Linux: http://www.mathworks.com/help/matlab/matlab_external/debugging-on-linux-platforms.html

Here are the directions for Windows: http://www.mathworks.com/help/matlab/matlab_external/debugging-on-microsoft-windows-platforms.html

NB: I am against referring the OP to a link off-site to help with his or her question. I usually include most of the answer in my posts and provide links as references. Because you haven't told me what platform you're using, I will not write solutions for all platforms as that will take too much time. As such (and I'm praying that the links are stable for a long time), you can refer to the appropriate link for your platform.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...