首页 > 解决方案 > glfw3 窗口在随机时间后冻结

问题描述

我有一些基本的 glfw 和 opengl 代码没有按预期运行的问题。窗口仅在至少几秒钟后才完全冻结,有时甚至更多。

我已经评论了几乎所有的代码,只剩下很少的几行。

初始化函数是:

int Renderer::init(std::string scene_file_ , RenderOptions options_)
{

    if(!glfwInit()){
        std::cout<<"Problem with GLFW"<< std::endl;
        glfwTerminate();
        return -1;
    }

    window = glfwCreateWindow(640,480, "raytracer", NULL, NULL);

    if(!window){
        std::cout << "Problem with window " << std::endl;
        glfwTerminate();
        return -1;
    }

    glfwMakeContextCurrent(window);


    glfwSwapInterval(2);
    glewInit();
}

绘图循环是:

void Renderer::displayScene()
{


    GLCall(glEnable(GL_DEPTH_TEST));
    int width, height;

    glfwGetFramebufferSize(window, &width, &height);

    GLCall(glViewport(0,0,width, height));

    GLCall(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
    GLCall(glClearColor(0.2,0.5,0.2,1.0));      

    printf("drawing %d\n", temp_inc_test++);

    glfwPollEvents();
    glfwSwapBuffers(renderer.window);
}

窗口开始正常,背景颜色正确,然后在〜3秒到〜5分钟之间,程序停止,窗口变得无响应。我很确定我已经运行了一些完全一样的代码,并且运行了几个小时。我不明白。

有什么明显的吗?我忘了提:我在 linux Jessie 上使用 rasberry PI

标签: c++linuxopenglraspberry-piglfw

解决方案


推荐阅读