Daniel L
Daniel L

Reputation: 178

Code after glfwTerminate() never runs

I've been trying some modern OpenGL tutorials, and I came across what seems to be strange behaviour. Here is the code, reduced to its (almost) bare essentials.

#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>

using std::cout;
using std::endl;

int main(){
    std::cout << "Begin program" << std::endl;
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL", 0, 0); // Windowed
    glfwMakeContextCurrent(window);
    glewExperimental = GL_TRUE;
    glewInit();

    while(!glfwWindowShouldClose(window))
    {
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    cout << "before glfwTerminate()" << endl;
    glfwTerminate();
    cout << "after glfwTerminate()" << endl; cout.flush();

    std::cout << "End program" << std::endl;
    return 0;
}

Looking at the GLFW docs, the call to glfwTerminate() should not exit the program, but nothing is output to the console after "before glfwTerminate()" and the program ends.

I'm on ArchLinux (freshly updated) and I tried with both xfce4 and KDE (minimal install for the latter, just to make sure it wasn't an xfce4 issue).

Would someone have a hint as to what is going on?

Upvotes: 2

Views: 787

Answers (1)

Amadeus
Amadeus

Reputation: 10655

It is not finishing the program. Indeed it is processing the lines after glfwTerminate(), but somehow glfw is changing how stdout is bound to output stream.

It is a bug. You can confirm this by changing cout to cerr

Upvotes: 3

Related Questions