GLFW closing window automatically

Viewed 32

I am trying to create a simple program using OpenGL

I have set up some key callbacks which is triggered everytime I run the code The main loop is

while (glfwWindowShouldClose(window) == 0)
{
    renderGL();
    glfwSwapBuffers(window);
    glfwPollEvents();
}
glfwTerminate();
return 0;

and the key_callback function has the line

if (key == GLFW_KEY_Q && action == GLFW_PRESS){ 
    glfwSetWindowShouldClose(window, GL_TRUE);
}

The code is working fine without it but if I close the window by pressing Q then then run it again then this block of code is executed and the window closes,

To stop it from happening if I remove it for once and run then again it starts working fine, What might be the problem here

1 Answers
Related