消息:
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 多次迭代后终止。上述函数仅在我的应用程序快结束时调用一次。我在调用上述函数之前调用了一个非常相似的函数,这不会导致问题。