调用完函数跳不出来,显示Run-Time Check Failure #0 - The value of ESP...

meshdeform 2007-01-11 10:11:28
先谢谢大家了。
我在下面这个语句里调用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);的哪里都会出语法错误,请高人指点一下呀,谢谢了。
...全文
8786 24 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[Quote=引用 23 楼 libillow 的回复:]

原因找到:
函数定义的调用规则,和实际的调用规则不同。如 编译器默认的是__cdecl,而__stdcall 类型的函数却用了 __cdecl 的调用规则,由于编译时不会报错,结果出现了运行时异常。

所以把在函数定义中进行设置调用规则即可解决此问题。

如: typedef void (__stdcall Foo)(int a);
[/Quote]

我遇到这个问题 不是__stdcall 而是用的WINAPI
libillow 2011-05-12
  • 打赏
  • 举报
回复
原因找到:
函数定义的调用规则,和实际的调用规则不同。如 编译器默认的是__cdecl,而__stdcall 类型的函数却用了 __cdecl 的调用规则,由于编译时不会报错,结果出现了运行时异常。

所以把在函数定义中进行设置调用规则即可解决此问题。

如: typedef void (__stdcall Foo)(int a);
libillow 2011-05-12
  • 打赏
  • 举报
回复
可问题是我重新编译了,问题还是一样。而且DLL的运行也正常。返回的数据类型也对。
libillow 2011-05-12
  • 打赏
  • 举报
回复
我感觉 楼上的讲得有道理,应该是版本的问题
鸵鸟 2010-06-30
  • 打赏
  • 举报
回复
你是不是用了另外的lib和DLL? 这个问题是由于编译那个dll的vc编译器版本和你当前的版本不一样引起的,
vs2005 和 vs 2005 sp1 的相互调用就会有这个问题
cattycat 2010-06-25
  • 打赏
  • 举报
回复
栈溢出或内存写错误了。
rixio 2010-06-25
  • 打赏
  • 举报
回复
1.-Add preprocessor GSL_DLL to MSVC
2.-Instantiate (CREATE) all the data inside the function local stack
new double[N];
gsl_vector X*=gsl_vector_alloc(....,...);
gsl_matrix C*=gsl_matrix_alloc(....,...);

This seems to solve the ESP bouncing.. and avoid to edit the DLL or whatever..

Rixio.
码农7号- 2009-09-16
  • 打赏
  • 举报
回复
我猜测是函数声明的参数少了
你调试的时候,不妨检查一下ESI和ESP的差值
如果ESP比ESI多4,表明你的函数声明比实际的少了1个参数
多8,少了2个参数
mybabyyuli 2009-01-15
  • 打赏
  • 举报
回复
顶,同样问题!
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 taodm 的回复:]
按提示,是栈溢出。
[/Quote]
有速度
zhiqiang0819 2009-01-15
  • 打赏
  • 举报
回复
越界了
knowledge_Is_Life 2008-05-01
  • 打赏
  • 举报
回复
我也想知道,正在找這方面的資料~~~~~
Walker-cheng 2008-04-24
  • 打赏
  • 举报
回复
出现这种问题,无非内存越界,栈益处....
solotek97 2008-04-24
  • 打赏
  • 举报
回复
佩服佩服。 。 原先遇到过栈溢出,但是症状不一样。
linux_is_perfect 2007-08-03
  • 打赏
  • 举报
回复
mochen5460(mochen)
这么厉害,几分钟就看出来了,强人,学习

zylfly 2007-08-03
  • 打赏
  • 举报
回复
共同关注,用的是VS 2005 。 调用GSL库的时候也出现了这个问题。函数里面的内存分配仅仅使用了是GSL 库里面的的函数,比如说矩阵。再函数返回时出错,没有跳回到调用函数。GSL库的版本是1.8
kenneth_lueng 2007-01-12
  • 打赏
  • 举报
回复
对于数组,请使用内存动态分配
或者使用std::vector<T &t>
  • 打赏
  • 举报
回复
越界,栈溢出。
mLee79 2007-01-11
  • 打赏
  • 举报
回复
某个地方内存越界鸟, 破坏了栈帧 ...
比如酱紫 :

#include <stdio.h>
#include <stdlib.h>

void foobar( int a )
{
volatile stack_frame[100] = {0};
stack_frame[ 100 ] -= 4;
}

int main()
{
int b = 100 , a[100] = {0};
printf( "%p %d.\n" , &b , b );
foobar( 1 );
printf( "%p %d.\n" , &b , b );
//exit(0);
}

参考这个 ... http://community.csdn.net/Expert/topic/5284/5284459.xml?temp=.1075556 ..
taodm 2007-01-11
  • 打赏
  • 举报
回复
或者说,有栈中变量内存越界,把esp值冲掉了。
加载更多回复(4)

65,182

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧