I've written a mex function named mx_minimum_power that I'm calling it in MATLAB as follows:
[Fs,Fd,pow_remained] = mx_minimum_power(A11,A12_real,A12_imag,A13_real,A13_imag,A22,A23_real,A23_imag,A33,MatSize);
- A11, A12_real, A13_real, A22, A23_real, A33 are
30555x1 singlematrices - A12_imag, A13_imag, A23_imag are
1x1 singlevariables - MatSize is a
1x1 doublevariable with the value30555, that is the size of matrices
In an iteration, each time the hermitian matrix A is constructed

and eigenvalues and eigenvectors of it should be found. So I've written the following gateway function with the help of CVM Class Library.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *arraysizePtr = NULL;
arraysizePtr = mxGetPr(prhs[9]);
const int arraysize = (int)*arraysizePtr;
const int matrixDimention = 3;
float *inMatrixA11 = (float *)mxGetPr(prhs[0]);
float *inMatrixA12_real = (float *)mxGetPr(prhs[1]);
float *inMatrixA12_imag = (float *)mxGetPr(prhs[2]);
float *inMatrixA13_real = (float *)mxGetPr(prhs[3]);
float *inMatrixA13_imag = (float *)mxGetPr(prhs[4]);
float *inMatrixA22 = (float *)mxGetPr(prhs[5]);
float *inMatrixA23_real = (float *)mxGetPr(prhs[6]);
float *inMatrixA23_imag = (float *)mxGetPr(prhs[7]);
float *inMatrixA33 = (float *)mxGetPr(prhs[8]);
basic_schmatrix< float, complex<float> > A(matrixDimention);
basic_scmatrix< float, complex<float> > EigenVectors(matrixDimention);
basic_rvector<float>EigenValues(matrixDimention);
int i = 0;
for (i = 0; i < arraysize; i++)
{
A.set(2, 2, inMatrixA11[i]);
A.set(2, 3, complex<float>(inMatrixA12_real[i], inMatrixA12_imag[0]));
A.set(2, 4, complex<float>(inMatrixA13_real[i], inMatrixA13_imag[0]));
A.set(3, 3, inMatrixA22[i]);
A.set(3, 4, complex<float>(inMatrixA23_real[i], inMatrixA23_imag[0]));
A.set(4, 4, inMatrixA33[i]);
try{ EigenValues = A.eig(EigenVectors);}
catch (cvmexception& ex) {
cout << ex.what() << endl;
}
}
}
until line 28 that is try{ EigenValues = A.eig(EigenVectors);}, here I get the run-time error:

and the control jumps to line 311 of the file cvm.h, that is line 11 of the following code:
CVM_NAMESPACE_BEG
//! %Array deleter helper class
template<typename T>
class ArrayDeleter {
public:
void operator () (T* d) const {
if (d != nullptr) {
::delete[] d;
}
}
};
seems that something causes the array get deleted before returning the control to the gateway function but I don't know what? Because if I stop debugging and return to MATLAB, I will get:

and if I press attempt to continue, I'll get:

so there's no way to see which exception is thrown through the try, catch and cout code.
Hint:
basic_schmatrixis a class in CVM library that is encapsulating hermitian matrices of complex numbers. See here, here and herebasic_scmatrixis a class in CVM library that encapsulates square matrices of complex numbers. See here, here and here, I've used it to allocate memory forEigenvectors, because they'll be returned in the form of a the square matrix

in which the columns are orthonormal eigenvectors.basic_rvectoris a class in CVM library for encapsulating vector of real numbers. It has been used to allocate memory for eigenvalues because as we know the eigenvalues of a hermitian matrix is real and they'll be returned in the form of the vector
I've used indices
2-4instead of1-3because as I've explained here CVM0=1- Finaly
eigis a member function of the classbasic_schmatrixthat gets the address to the allocated memory for eigenvectors and returns an object of typervector, please see here
EDIT :
from my inspections it's not an error. The control should normally reach line 311 of the file CVM.h, because it is using dynamic memory allocation and it's going to release resources when returning to the gateway function here's a list of where the control goes when you press F11s and it's not throwing an exception at all. But what's wrong with my gateway function code that causes matlab encounter such a breakpoint?