Unable to read memory- unable to read size[0]

-2

I have my C code and C code generated from MATLAB (only 1 function). When I run the program and pass arguments, the program returns an error of access violation reading location 0x00000000. I couldn't understand what to pass as argument

function novi_niz= fft_matlab(br,niz_i)
novi_niz=zeros(br,1);

while(uint16(br))
novi_niz(br)=abs(fft(niz_i(br)))/br;
br=br-1;
end
end

Source

emxArray_real_T novi_niz = *malloc(4200 * sizeof(emxArray_real_T)); // before main of my program

//////calling function somewhere in main////
fft_matlab(nfft, niz_i,novi_niz);

/////////fft_matlab.h////////
extern void fft_matlab(unsigned short br, const short niz_i[4200],
        emxArray_real_T *novi_niz);

//////fft_matlab source/////////
void fft_matlab(unsigned short br, const short niz_i[4200],
        emxArray_real_T *novi_niz) {
    int i0;
    int loop_ub;
    unsigned short u0;
    i0 = novi_niz->size[0];  // THIS IS LINE WHEN PROGRAM CRASH and says 
    novi_niz->size[0] = br;
    emxEnsureCapacity_real_T(novi_niz, i0);

It says that it is unable to read and when I look at data and size variables they are 0x00000000. This was supposed to be output of function that was on beginning of program initialized to all zeros with novi_niz=zeros(br,1), and after that written into .

c
visual-studio
matlab
allocation
asked on Stack Overflow Aug 30, 2019 by Alexandar13 • edited Aug 30, 2019 by John Bollinger

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0