调用完函数跳不出来,显示Run-Time Check Failure #0 - The value of ESP...
先谢谢大家了。
我在下面这个语句里调用plane类的函数。
plane.doPlaneFitAdaptiveWeight(this->nbHood, this->positions[j], this->numberOfNeighbours);
doPlaneFitAdaptiveWeight的定义如下:
void PlaneFit::doPlaneFitAdaptiveWeight(NeighbourHood *nbHood, const Vector3D& source, int nofNeighbours) {
float param;
if (!nbHood) {
return;
}
nbHood->setNofNeighbours(nofNeighbours);
nbHood->setSourcePoint(source);
// calc param adaptive ( - ln 0.05 =~ 3)
param = nbHood->getSquaredDistance(nofNeighbours - 1) / 3.0;
//doPlaneFit(nbHood,source,nofNeighbours,param);
gsl_matrix *data_matrix;
gsl_matrix *transposed_data_matrix;
gsl_matrix *covariance_matrix;
gsl_matrix *eigen_vectors;
gsl_vector *eigen_values;
gsl_eigen_symmv_workspace *workspace;
int i;
float *weights;
float totalweight;
// matrix init:
data_matrix = gsl_matrix_calloc(3,nofNeighbours);
transposed_data_matrix = gsl_matrix_calloc(nofNeighbours, 3);
covariance_matrix = gsl_matrix_calloc(3,3);
eigen_vectors = gsl_matrix_calloc(3,3);
eigen_values = gsl_vector_calloc(3);
workspace = gsl_eigen_symmv_alloc(3);
if (!nbHood) {
return;
}
//nbHood->setNofNeighbours(nofNeighbours);
//nbHood->setSourcePoint(source);
weights = new float[nofNeighbours];
totalweight = 0;
_center = Vector3D(0.,0.,0.);
if (param == 0) {
return;
}
for (i = 0; i < nofNeighbours; i++) {
Vector3D vec = nbHood->getNeighbourPosition(i);
float current_distance = Vector3D::distance(vec, source);
weights[i] = exp(-(current_distance*current_distance) / param);
totalweight += weights[i];
gsl_matrix_set(data_matrix,0,i,vec[0]);
gsl_matrix_set(data_matrix,1,i,vec[1]);
gsl_matrix_set(data_matrix,2,i,vec[2]);
_center += vec * weights[i];
}
if (totalweight == 0) {
return;
}
_center /= totalweight;
for (i = 0; i < nofNeighbours; i++) {
gsl_matrix_set(data_matrix, 0, i, (gsl_matrix_get(data_matrix,0,i) - _center[0])*weights[i]);
gsl_matrix_set(data_matrix, 1, i, (gsl_matrix_get(data_matrix,1,i) - _center[1])*weights[i]);
gsl_matrix_set(data_matrix, 2, i, (gsl_matrix_get(data_matrix,2,i) - _center[2])*weights[i]);
}
gsl_matrix_transpose_memcpy(transposed_data_matrix, data_matrix);
gsl_matrix_const_view data_matrix_view = gsl_matrix_const_submatrix(data_matrix, 0,0, 3, nofNeighbours);
gsl_matrix_const_view transposed_data_matrix_view = gsl_matrix_const_submatrix(transposed_data_matrix, 0,0, nofNeighbours, 3);
// get covariance matrix
gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, &data_matrix_view.matrix, &transposed_data_matrix_view.matrix, 0.0, covariance_matrix);
// calculate eigenvectors/eigenvalues of the covariance matrix
gsl_eigen_symmv(covariance_matrix, eigen_values, eigen_vectors, workspace);
gsl_eigen_symmv_sort(eigen_values, eigen_vectors, GSL_EIGEN_SORT_VAL_ASC);
_eigenvalues[0] = gsl_vector_get(eigen_values, 0);
_eigenvalues[1] = gsl_vector_get(eigen_values, 1);
_eigenvalues[2] = gsl_vector_get(eigen_values, 2);
// set up plane equation
_normal[0] = gsl_matrix_get(eigen_vectors,0,0);
_normal[1] = gsl_matrix_get(eigen_vectors,1,0);
_normal[2] = gsl_matrix_get(eigen_vectors,2,0);
_normal.normalize();
_d = -1.*(_normal[0]*_center[0]+_normal[1]*_center[1]+_normal[2]*_center[2]);
_isvalid = true;
gsl_matrix_free(data_matrix);
gsl_matrix_free(transposed_data_matrix);
gsl_matrix_free(covariance_matrix);
gsl_matrix_free(eigen_vectors);
gsl_vector_free(eigen_values);
gsl_eigen_symmv_free(workspace);
}
可是就在函数跳出时(运行到最后一个括号),错误,显示Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
我查了一下,说有可能需要在函数调用时加上__stdcall,但是我也不知道是不是这个问题,我这里面调用了一个gsl库,用的dll和lib,跟那个有关还是我函数的本身的问题。
另外我在调用时无论把__stdcall放在plane.doPlaneFitAdaptiveWeight(this->nbHood, this->positions[j], this->numberOfNeighbours);的哪里都会出语法错误,请高人指点一下呀,谢谢了。