这个信息:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
我查看了gdb的回溯信息,这是我自己实现的最低级别方法:
/*
* get an array of vec3s, which will be used for rendering the image
*/
vec3 *MarchingCubes::getVertexNormalArray(){
// Used the same array size technique as getVertexArray: we want indices to match up
vec3 *array = new vec3[this->meshPoints.getNumFaces() * 3]; //3 vertices per face
int j=0;
for (unsigned int i=0; i < (this->meshPoints.getNumFaces() * 3); i++) {
realVec normal = this->meshPoints.getNormalForVertex(i);
// PCReal* iter = normal.begin();
if (normal.size() >= 3) {
array[j++] = vec3(normal[0], normal[1], normal[2]);
}
cout << i << " ";
}
return array;
}
你在上面看到的cout语句表示它在7000多次迭代后终止。 上述函数仅在我应用程序的末尾附近调用一次。 在调用上述函数之前,我调用了一个非常类似的函数,但没有引起问题。
delete[]
释放这个函数返回的数组吗? - Matteo ItaliameshPoints.getNumFaces()
的大小是多少?vec3
的大小又是多少? - celtschkj
是否始终保持在meshPoint.getNumFaces()*3
以下吗?也许你会因为缓冲区溢出而覆盖了必要的堆结构,从而导致bad_alloc
。 - celtschkj
怎么样? - celtschk