0

我正在使用 glut 制作一个简单的游戏。过剩显示回调如下所示:

std::chrono::duration<float> timeDelta = std::chrono::high_resolution_clock::now() - lastFrame;
lastFrame = std::chrono::high_resolution_clock::now();
std::cout << (1 / timeDelta.count()) << "fps" << std::endl; // print fps

game->draw();

std::cout << "finished frame"  << std::endl << std::endl;

glutSwapBuffers();

由于某种原因,该函数永远不会完成,控制台输出如下所示:

166.639fps
draw game
166.667fps
draw game

无限重复。

draw函数如下所示:

std::cout << "draw game" << std::endl;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glClearColor(RENDER_BRIGHTNESS, RENDER_BRIGHTNESS, RENDER_BRIGHTNESS, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

camera.draw();
world.draw();

//Bind 0, which means render to back buffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);

glViewport(0, 0, width, height);

glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glBindTexture(GL_TEXTURE_2D, frameTexture);
glGenerateMipmap(GL_TEXTURE_2D);

glBegin(GL_QUADS);
    glColor4d(1, 1, 1, 1);
    glTexCoord2d(0, 0); glVertex2d(0, 0);
    glTexCoord2d(1, 0); glVertex2d(width, 0);
    glTexCoord2d(1, 1); glVertex2d(width, height);
    glTexCoord2d(0, 1); glVertex2d(0, height);
glEnd();

camera.draw()简单地操作 gls 矩阵。该函数使用平截头体剔除(从此处复制:httpworld.draw() ://www.crownandcutlass.com/features/technicaldetails/)遍历八叉树的节点(使用此实现: http: //nomis80.org/code/octree.html ) frustum.html ) 并将叶子绘制为立方体。

draw gamegame->draw()函数打印。finished frame从不打印。看起来该game->draw()函数递归调用显示函数,即使它位于不同的文件中并且没有指向它的指针。甚至可以用代码存档这种效果吗?这是 mingw-g++ 中的错误吗?

八叉树经常使用不安全函数 reinterpret_cast。这可能是问题的根源吗?

我希望没有必要发布完整的源代码,因为它非常庞大。

4

1 回答 1

0

这是一篇关于调试调用堆栈损坏的有用文章http://hisham.hm/2012/02/14/debugging-a-stack-corruption-with-gdb/ 原来取消引用悬空指针导致了问题。

于 2013-07-22T18:18:53.000 回答