Matlab crashes when manipulating an array generated by a mex function
古いコメントを表示
Dear all,
I have written a Mex-function that generates an array. Actually, it is a topological sort algorithm. Now let's say I call this function
A = tsort(B); % contains a call to the mex function
A = otherfunction(A); % other function that modifies A contains only matlab code
then it happens quite often that Matlab crashes when calling otherfunction, even after minutes between my call to tsort and otherfunction. Did anyone experience such problems with his or her code. By the way, I am using Windows 7 64bit, Matlab 2012a and Microsoft Software Development Kit (SDK) 7.1 as compiler.
Thanks for your help, Anon
8 件のコメント
Walter Roberson
2013 年 1 月 22 日
We will probably need to see your tsort() code.
There are some common errors that people tend to make in mex code that show up the next time that MATLAB tries to allocate or deallocate memory, such as if another function is called.
Anon
2013 年 1 月 22 日
Anon
2013 年 1 月 23 日
James Tursa
2013 年 1 月 23 日
Probably several people have looked at this post and had the same reaction that I had. Basically, it is not obvious from looking at the code where the indexes used would become invalid. So I would suggest putting in a lot of checks in the code to detect a problem and print it out. Everywhere you index into an array, put a check. E.g., check to see that SN, ix, ixc, and MV are not NULL. Check to see that IXN is not too large just before you do SN[IXN]. Check to see that pix1 is not too large just before before you do ixc[pix1] and ix[pix1]. Etc. My guess is that eventually you will get a message to the screen telling you where the problem is.
Anon
2013 年 1 月 24 日
Just an idea to check. Your mexFunction gives back Data of type
mxUINT32_CLASS
Matlab use double as standard, as far as I know. I do convert integers, which should be given back to matlab from my mexFunction, to doubles before. Otherwise you have to work with int32() in matlab. This is just an idea...
Anon
2013 年 1 月 24 日
James Tursa
2013 年 1 月 24 日
@anon: The mex function is likely corrupting memory but that corruption isn't detected until later on after the mex routine has returned control back to MATLAB. E.g., the mex routine might have corrupted another variable in the workspace that has nothing to do with the mex routine, and it isn't until you get back to MATLAB and do downstream stuff that the error has an effect and crashes MATLAB. If you are unfamiliar with debugging then I suggest you follow my advice and put in lots of checks all over your code to detect when you are out-of-bounds or dereferencing a NULL pointer etc.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!