title: glfw how to destroy window in mainloop
body: <p>I am trying to develop a program using glfw where the window closes in the main loop. However, I get this weird run time error:</p>
  
  <pre><code>X Error of failed request:  GLXBadDrawable
    Major opcode of failed request:  152 (GLX)
    Minor opcode of failed request:  11 (X_GLXSwapBuffers)
    Serial number of failed request:  158
    Current serial number in output stream:  158
  </code></pre>
  
  <p>Here is the code I'm trying to run</p>
  
  <pre><code>#include &lt;GL/glfw3.h&gt;
  
  int main()
  {
      GLFWwindow* window;
  
      if(!glfwInit())
          return -1;
  
      window = glfwCreateWindow(400, 400, "window", nullptr, nullptr);
  
      if(!window)
      {
          glfwTerminate();
          return -1;
      }
  
      glfwMakeContextCurrent(window);
  
      while(!glfwWindowShouldClose(window))
      {
          glfwDestroyWindow(window);
  
          glfwSwapBuffers(window);
  
          glfwPollEvents();
      }
  
      glfwTerminate();
      return 0;
  }
  </code></pre>
  
  <p>Is there any way to destruct the window from inside the main loop?</p>