I call a mex function and do some operations with its results and then matlab crashes

1 次查看(过去 30 天)
I create a mex function to use a subroutine I code in C++. I compiled without errors. Then run an example have a correct answer, then modify the answer, create a figure with the answer seconds after it Matlab crashes. Here is the code:
row=145;col=145;
nn=row*col
i = 1; b1=b((i-1)*nn+1:i*nn);
[sol,iter,relres1]= BiCGStabNineDiag(Diag,DiagLU,b1,row,tol,maxit); %mexFunction
sol=reshape(sol,row,col);
figure,imshow(sol,[])
There is a message from windows saying that there is an error and it has to close matlab. After it I found a log file. describing problems with Java y netdll.dll
#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000077aeec75, pid=3636, tid=2068
#
# Java VM: Java HotSpot(TM) 64-Bit Server VM (11.2-b01 mixed mode windows-amd64)
# Problematic frame:
# C [ntdll.dll+0x4ec75]
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
After that there is a lenghty description of the thread and registers, etc. I am checking my mexFunction but the answers are correct and since it changes the vector sol to a matrix and then shows its image I thought it does not have to do with my mex function. But before this mablab never crashed then I suspect it has something to do with destroying the output. I used this at the end of my mexFunction
mxDestroyArray(plhs[0]);
mxDestroyArray(plhs[1]);
mxDestroyArray(plhs[2]);
but I got the same results. I would appreciate any help.

回答(1 个)

James Tursa
James Tursa 2012-1-13
You should never use mxDestroyArray on any of the plhs[*] values ... that will guarantee a MATLAB crash since MATLAB will attempt to use invalid memory downstream. I would hazard a guess that you may have other problems in your mex code as well, so I would suggest posting it.
  1 个评论
Maider Marin
Maider Marin 2012-1-13
thanks, very much. I used mxDestroyArray out of desperation. But I suppose you are right since matlab behave the same without the mxDestroyArray lines. The function with everything (structs, sub-routines, main function and mex) is about 560 lines. I will try to put the essentials.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by