Stack overflow in mex

8视图(30天)
Hi Friends,
I have one confusion regarding a mex code. The code is giving me a segmentation fault.
include
包括
include
include
voidmexFunction(int nlhs,mxArray *outputs[],int nrhs,const mxArray *prhs[])
{
const mxArray *R_locpr,*Nbpscpr,*mlpr,*Sym_x3_searchpr,*kmodpr,*fxpr,*fp_rsym_fmt_prodpr;
int R_loc_rowLen,R_loc_colLen,Sym_x3_search_rowLen,Sym_x3_search_colLen,i,j;
double *R_locr,*R_loci,*dmp_fmt_values,resolution,R_23_loc_in_cncr,R_23_loc_in_cnci,R_13_loc_in_cncr,R_13_loc_in_cnci,R_12_loc_in_cncr,R_12_loc_in_cnci;
double*nbpsc,*kmod,*fxp,*fp_rsym_fmt_prod,*sym_x3_searchr,*sym_x3_searchi,*dummyr,*dummyy,*sym_locr,*sym_locr,*sym_loci;
double complex *SYM_loc,*Sym_x3_search,*R_loc,R_23_loc_in_cnc,R_13_loc_in_cnc,R_12_loc_in_cnc,c;
mxArray *dmp_fmt,*rsym_prod,*xData[2],*array_ptr ;
int *ml;
R_locpr=prhs[5];
R_locr=mxGetPr(R_locpr);
r_loci = mxgetPi(r_locpr);
R_loc_rowLen=mxGetN(R_locpr);
R_loc_colLen=mxGetM(R_locpr);
为了(i=0;i
{
为了(j=0;j
{
R_loc[i*R_loc_rowLen+j]=R_locr[i*R_loc_rowLen+j]+R_loc[i*R_loc_rowLen+j]*_Complex_I;
}
}
dmp_fmt = mexgetVariable("caller",,,,"fp_x_dmp_fmt");
if(dmp_fmt==NULL)
{
mexErrMsgTxt("Could not get fp_x_dmp_fmt from MATLAB workspace.");
}
else
{
dmp_fmt_values=mxGetPr(dmp_fmt);
resolution = pow(0.5,dmp_fmt_values[1]);
}
if(r_loc_collen == 3)
{
R_23_loc_in_cnc=R_loc[7];
R_13_loc_in_cnc=R_loc[6];
}
R_12_loc_in_cnc=R_loc[3];
mlpr=prhs[14];
Nbpscpr=prhs[3];
ml=mxGetPr(mlpr);
Nbpsc=mxGetPr(Nbpscpr);
Sym_x3_searchpr=prhs[1];
Sym_x3_searchr=mxGetPr(Sym_x3_searchpr);
Sym_x3_searchi=mxGetPi(Sym_x3_searchpr);
sym_x3_search_rowlen = mxgetn(sym_x3_searchpr);
Sym_x3_search_colLen=mxGetM(Sym_x3_searchpr);
为了(我= 0;< Sym_x3_search_colLen;i++)
{
为了(j=0;j
{
Sym_x3_search[i*Sym_x3_search_rowLen+j]=Sym_x3_searchr[i*Sym_x3_search_rowLen+j]+Sym_x3_searchi[i*Sym_x3_search_rowLen+j]*_Complex_I;
}
}
kmodpr = prhs [4];
printf("%d\n",,,,mxGetN(kmodpr));
printf("%d",,,,mxGetM(kmodpr));
kmod=mxGetPr(kmodpr);
if(kmodpr==NULL)
{
mexErrMsgTxt(“无法从Matlab工作区获得KMOD。”);
}
FXPR = PRHS [13];
fxp=mxGetPr(fxpr);
fp_rsym_fmt_prodpr = mexgetVariable("caller",,,,"fp_rsym_prod_fmt");
if(fp_rsym_fmt_prodpr==NULL)
{
mexErrMsgTxt("Could not get fp_rsym_prod_fmt from MATLAB workspace.");
}
else
{
fp_rsym_fmt_prod=mxGetPr(fp_rsym_fmt_prodpr);
}
if(r_loc_collen == 3)
{
为了(我= 0;< Sym_x3_search_colLen;i++)
{
为了(j=0;j
{
SYM_loc[i*Sym_x3_search_rowLen+j]=0;
}
}
}
}
这里is the log file:
----------------------------------------------------------------------------------------------------------------------
Segmentation2012年9月28日星期五发现的违规行为
------------------------------------------------------------------------------------------------------------------
Configuration:
MATLABVersion:7.5.0.338(R2007b)
MATLABLicense:XXXXXX
Operating系统:Linux 2.6.20-1.2962.fc6 #1 SMP Tue Jun 19 19:27:14 EDT 2007 i686
gnuC库:2.5稳定
Window系统:这X.Org Foundation (70101000),,,,display:0.0
CurrentVisual:0x23(第4类,深度24)
ProcessorID:x86 Family 15 Model 4 Stepping 7,,,,GenuineIntel
Virtual机器:Java 1.6.0 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode,,,,sharing
DefaultCharset:UTF-8
登记State:
eax = 00000400 ebx = 00afdbd0
ecx = 08b5a5f0 edx = 00000000
ESI = 08B5A3F0 EDI = 00000040
EBP = 054CA198 ESP = 054CA120
eip = 00afc80e flg = 00010206
StackTrace:
[0] list_decode.mexglx:mexFunction~(0, 0x054caa44, 15, 0x054caaa4) + 370 bytes
[1] libmex.so:mexRunMexFile(0, 0x054caa44, 15, 0x054caaa4) + 111 bytes
[2] libmex.so:Mfh_mex::runMexFileWithSignalProtection(int, mxArray_tag**, int, mxArray_tag**)(0x08e887e0, 0, 0x054caa44, 15) + 120 bytes
[3] libmex.so:mfh_mex:: dispatch_file(Int,mxarray_tag **,int,mxarray_tag **)(0x08e887e0,0,0x054caa44,15)
[4] libmwm_dispatcher.so:Mfh_file::dispatch_fh(int, mxArray_tag**, int, mxArray_tag**)(0x08e887e0, 0, 0x054caa44, 15) + 217 bytes
[5] libmwm_interpreter.so :: resolverfunctiondesc :: callfunction(Int,mxarray_tag **,int,mxarray_tag **)(0x054cb024,0,0,0x054CAA44,15) + 808 bytes + 808 bytes
[6] libmwm_interpreter.so:Resolver::CallMFunction(int, int,_m_operand*, m_operand_storage*, int,_m_operand*, m_operand_storage*, int*)(0x054cac00, 0, 1, 0xb27ed090) + 1530 bytes
[7] libmwm_interpreter.so:inResolveMFunctionCall(_m_function_desc*, int, int,_m_operand*, m_operand_storage*, int,_m_operand*, m_operand_storage*, int*, inMarshalType*, int, mpsTypeSequenceNlhs const*, mxArray_tag* (*)(int))(0xb26e50b0, 0, 1, 0xb27ed090) + 461 bytes
[8] libmwm_interpreter.so:accelImpl::MFunctionCall(_ACCELOP **)(0x054CB148,0x054CB160,0,0x08d3cb68) + 216字节
[9] libmwm_interpreter.so:accelImpl::Exec()(0x054cb148, 0xb26d9a88, 0x054cb158, 0xb2600000) + 215 bytes
[10] libmwm_interpreter.so:accelCode::Call(inMarshalType*, int*) const(0xb2a36f80, 0x054cb320, 0x054cb31c, 0x015149a0) + 105 bytes
[11] libmwm_interpreter.so:inJit::ExecuteHotSegment(_inJitAccelInfo*, opcodes*, int*, int*)(0x054cb4a4, 0x054cb4ec, 0x054cb4bc, 0x054cb94c) + 1393 bytes
[12] libmwm_interpreter.so:.l752(1,0,6,0) + 158字节
[13] libmwm_interpreter.so:protected_inInterp(inDebugCheck, int, int, opcodes, inPcodeNest_tag*, int*)(1, 0, 1, 0) + 121 bytes
[14] libmwm_interpreter.so:inInterPcodeSJ(inDebugCheck, int, int, opcodes, inPcodeNest_tag*, int*)(0, 0xb2bc6690, 0x054cb94c, 0x054cb94c) + 297 bytes
[15] libmwm_interpreter.so:inExecuteMFunctionOrScript(Mfh_mp*, bool)(0x08d76a20, 1, 0x054cbc6c, 0) + 625 bytes
[16] libmwm_interpreter.so:inRunMfile(int, mxArray_tag**, int, mxArray_tag**, Mfh_mp*, inWorkSpace_tag*)(0, 0x054cbc6c, 0, 0x054cbccc) + 640 bytes
[17] libmwm_interpreter.so:Mfh_mp::dispatch_file(_mdUnknown_workspace*, int, mxArray_tag**, int, mxArray_tag**)(0x08d76a20, 0, 0, 0x054cbc6c) + 64 bytes
[18] libmwm_interpreter.so:mfh_mp:: dispatch_file(Int,mxarray_tag **,int,mxarray_tag **)(0x08d76a20,0,0x054cbc6c,0 x 0x054cbc6c,0) + 54 bytes + 54 bytes
[19] libmwm_dispatcher.so:Mfh_file::dispatch_fh(int, mxArray_tag**, int, mxArray_tag**)(0x08d76a20, 0, 0x054cbc6c, 0) + 217 bytes
[20] libmwm_interpreter.so:inDispatchFromStack(int, char const*, int, int)(620, 0x08e91034“ mexcallfunctionmatlab”,,,,0,,,,0) + 1078 bytes
[21] libmwm_interpreter.so:indisPatchCall(Char const*,int,int,int,int*,int*)(0,0,0x054cbfb8,0x08e91028,0x00b270f9) + 160字节
[22] libmwm_interpreter.so:.l777(2,0,0,0,0) + 165字节
[23] libmwm_interpreter.so:protected_inInterp(inDebugCheck, int, int, opcodes, inPcodeNest_tag*, int*)(2, 0, 0, 0) + 121 bytes
[24] libmwm_interpreter.so:ininterpcodesj(indebugcheck,int,int,opcodes,inpcodenest_tag*,int*)(0,0,0xb2bc48e0,0x054cc3e8,0x054cc3e8,0x00f4ebf0) + 297 bytes + 297 bytes + 297 bytes bytes
[25] libmwm_interpreter.so:inInterPcode(2, 0, 0x01063090, 0x01062310) + 158 bytes
[26] libmwm_interpreter.so:ininevalstringwithisvarfcn(_memory_context*, char const*, EvalType, int, mxArray_tag**, inDebugCheck,_pcodeheader*, int*, bool (*)(void*, char const*), void*, bool)(0x00fc4648", 0x08e145a0 "mexcallfunctionmatlab\n", 0, 0) + 2892 bytes
[27] libmwm_interpreter.so:inEvalCmdWithLocalReturnandtype(char const*, int*, inDebugCheck, bool)(0, 0, 0xb3242d80, 0x00d6ba28) + 149 bytes
[28] libmwbridge.so:ThrowSignal(char const*)(0x08e145a0"mexcallfunctionmatlab\n",2,0x054CD06C", 0x008237c4) + 99 bytes
[29] libmwbridge.so:mnparser(0x054CD0F0,0x08A8FC48,1,0x00559BC2) + 277字节
[30] libmwmcr.so:mcrInstance::mnParser()(0x08a8fc48, 0x054cf388, 0x08a8fc38, 0x08a42b90) + 52 bytes
Thiserror was detected while a MEX-file was running. If the MEX-file
is不是官方的数学功能,,,,pleaseexamine its source code
为了errors. Please consult信息信息指南
on调试Mex-Files。
If这是官方的数学功能,,,,please
followthese steps to report this problem to The MathWorks so we
havethe best chance of correcting it:
下次MATLAB在典型用法中启动,,,,a对话框将
opento help you send the error log to The MathWorks. Alternatively, 你
cansend an e-mail to segv@mathworks.com with the following file attached:
matlab_log
If问题是可重现的,,,,pleasesubmit a Service Request via:
//www.tatmou.com/金宝appsupport/contact_us/ts/help_request_1.html
一个technical support engineer might contact you with further information.
Thank您寻求帮助。保存您的工作区并重新启动MATLAB。
任何有关于这个问题的想法或者说如何to look stack file.
谢谢。
4 Comments
Jan
Jan on 26 Jan 2018
@JasonLuo: And the solution will be similar to the posted method: Use a debugger to identify the problem. Obviously your C code contains a bug. As long as you do not show us the code (in a new thread - do not hijack this one), all we can do is to suggest to find and fix it.

Sign in to comment.

一个ccepted Answer

Jan
Jan on 3 Oct 2012
您可以使用C型补充器的调试器找到该行,这会导致问题。另一个想法是插入一些mexprintf()命令,直到找到错误为止。
即使将其格式正确,该代码也很难阅读。例如。您通过 mexGetVariable("caller", "fp_x_dmp_fmt"); ,,,,which is ugly. Some spaces would increase the readability substantially. Therefore I do not expect, that a forum user will analyze the cause of your troubles.

More Answers (3)

priyadharshini p
priyadharshini p on 13 Sep 2019
clear pcode;
clear classes;
mypi = raspi;
mycam = cameraboard(mypi,'Resolution','1280x720');
ii = 1:1000
img = snapshot(mycam);
imagesc(img);
drawnow
结尾
mycam.Rotation = 180;
videoFrame = record(mycam,'myvideo.avi',60);
为了eground = step(foregroundDetector,videoFrame);
imwrite(videoFrame,'D:\referenceimage.jpg','jpg');
videoPlayer = vision.VideoPlayer('Name', 'Detected Cars');
videoPlayer.Position(3:4) = [650,400]; % window size: [width, height]
se = strel('square', 3); % morphological filter for noise removal
referenceImage = imread('d:\ referentimage.jpg');
X=zeros(2,121);
Y=zeros(2,121);
Z=zeros;
while ~isDone(videoReader)
frame = step(videoReader); % read the next video frame
% Detect the foreground in the current video frame
为了eground = step(foregroundDetector, frame);
% Use morphological opening to remove noise in the foreground
filteredForeground = imopen(foreground, se);
%-----------------------SPEED ---------------------------%
frame2=((im2double(frame))-(im2double(referenceimage)));
frame1=im2bw(frame2,0.1);
[labeLimage] = bwlabeln(frame1);
stats=regionprops(Labelimage,'basic');
BB=stats.BoundingBox;
i=2; %fblasst for
X(i)=BB(1);
Y(i)=BB(2);
Dist=((X(i)-X(i-1))^2+(Y(i)-Y(i-1))^2)^(1/2);
Z(i)=Dist;
M =中值(Z);
%disp(M);
%clc;
%disp('speed=')
Speed=((M)*(120/8))/(4);
%disp(Speed);
%SPEED = M ???????????
i = i + 1;
SE = strel('disk',6);
frame3=imclose(frame1,SE);
step(videoReader);
pause(0.05);
%if(i==121) end; ??
%-----------------------SPEED ---------------------------%
% Detect the connected components with the specified minimum area, and
% compute their bounding boxes
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', true, 'CentroidOutputPort', true, ...
'MinimumBlobArea', 150);
%bbox = step(blobAnalysis, filteredForeground);
[areas, centroids, bbox] = step(blobAnalysis, filteredForeground);
% Draw bounding boxes around the detected cars
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
% Display the number of cars found in the video frame
%ICI
%disp(centroids); //show...
%disp(size(centroids));//show....
numcars = size(bbox,1);%汽车 ...
numCars_str = ['car number:', num2str(size(bbox, 1))];
speed_str = [num2str(Speed),'KM/h'];
结果= insertText(结果,[10,10],numcars_str,'Boxopacity',1,...
'FontSize', 14);
对于i = 1:size(bbox,1)
result1 = insertText(result,[centroids(i,1),centroids(i,2)], speed_str, 'BoxOpacity', 1, ...
'FontSize', 20);
step(videoPlayer, result); % display the results
disp('numCars');
disp(numCars)
step(videoPlayer, result1);
disp('speed');
disp(speed_str);
%在整个框架中找到汽车总数
为了ii=1:length(videoFrame)%numof frames
totalcount(ii)=videoFrame(ii);
结尾
totcars=sum(totalcount)/5;
结尾
结尾
disp('Total number of cars in entire video')
disp(round(totcars));
停止(mycam);
getFile(mypi,'myvideo.avi','E:\mat');
error
Error using raspi.internal.cameraboard/record
Too many output arguments.
Error in mm (line 11)
videoFrame = record(mycam,'myvideo.avi',60);
1条评论
史蒂文·洛德(Steven Lord)
这与原始问题无关。请使用页面顶部的“询问链接”以新问题发布您的代码。

Sign in to comment.


priyadharshini p
priyadharshini p on 13 Sep 2019
Error using raspi.internal.cameraboard/record
Too many output arguments.
Error in mm (line 11)
videoFrame = record(mycam,'myvideo.avi',6 0);

priyadharshini p
priyadharshini p on 13 Sep 2019
How to solve this error

标签

Community Treasure Hunt

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

Start Hunting!