我有这个 for 循环:
for(int l = 0; l < level_max; ++l) {
//...
indexCount[l] = (2*patch_size_level+1) * (patch_size_level - 1);
GLuint* indices = new GLuint[indexCount[l]];
//... (for loops in which I fill indices)
delete[] indices;
}
(完整的代码片段可以在这里找到:https://gist.github.com/1915777)
出于某种原因,这会在 GLuint* indices = new GLuint[indexCount[l]];
处引发以下内存异常
Demo(12783,0x7fff7367e960) malloc: * error for object 0x1028cd408: incorrect checksum for freed object - object was probably modified after being freed.
我做错了什么?我没有为我的索引数组分配超过 indexCount[l]
的值。 (我检查过这个)。如何在这样的循环中正确删除动态数组。
谢谢
最佳答案
可能不相关,但此行可能存在读取缓冲区溢出:
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GL_UNSIGNED_INT) * indexCount[l], indices, GL_STATIC_DRAW);
我不知道 sizeof(GL_UNSIGNED_INT)
与您系统上的 sizeof(GLuint)
相比如何,但请检查您的代码是否存在此类错误。
关于c++ - for 循环中的动态数组分配会引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9452243/