# glfwSwapBuffers 1282 when window is closed

**URL:** <https://discourse.glfw.org/t/glfwswapbuffers-1282-when-window-is-closed/276>\
**Category:** support\
**Created:** [May 10, 2011, 1:00pm UTC](https://discourse.glfw.org/t/glfwswapbuffers-1282-when-window-is-closed/276 "2011-05-10T13:00:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 10, 2011, 1:00pm UTC](https://discourse.glfw.org/t/glfwswapbuffers-1282-when-window-is-closed/276/1 "2011-05-10T13:00:55Z")

</div>

**[mariojmartin](https://sourceforge.net/u/mariojmartin/)** wrote on [Tuesday, May 10, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/463e0518/#5d39):

Hi,

I know that tracking OpenGL errors is a pain, but I have noticed that  
glfwSwapBuffers() throws an error when the window is closed. It is a small  
issue, nevertheless. The code is something like this:

```
while (running == 1){
        glfwGetWindowSize(&screen_width, &screen_height);
        resize(screen_width, screen_height);
        display();
        glFlush();
        er = glGetError();
        glfwSwapBuffers();
        er = glGetError();
        if (er != GL_NO_ERROR){
            _handle_error_("\nOpenGL error : %i", er); 
        }
        glFinish();
	glfwSleep(0.05);
        // Checks is the window is still active 
	running = glfwGetWindowParam( GLFW_OPENED );
}
```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 10, 2011, 1:16pm UTC](https://discourse.glfw.org/t/glfwswapbuffers-1282-when-window-is-closed/276/2 "2011-05-10T13:16:31Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Tuesday, May 10, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/463e0518/#aecd):

How do you know that the error is caused by glfwSwapBuffers if you don’t check  
the value of er before calling it?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 10, 2011, 1:21pm UTC](https://discourse.glfw.org/t/glfwswapbuffers-1282-when-window-is-closed/276/3 "2011-05-10T13:21:06Z")

</div>

**[mariojmartin](https://sourceforge.net/u/mariojmartin/)** wrote on [Tuesday, May 10, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/463e0518/#a966):

Because I call glGetError() above, which clears all previous error messages  
from OpenGL.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 10, 2011, 1:32pm UTC](https://discourse.glfw.org/t/glfwswapbuffers-1282-when-window-is-closed/276/4 "2011-05-10T13:32:04Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Tuesday, May 10, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/463e0518/#e5f4):

This is true. My bad.

Which platform is this? Which version of GLFW are you using?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 10, 2011, 1:34pm UTC](https://discourse.glfw.org/t/glfwswapbuffers-1282-when-window-is-closed/276/5 "2011-05-10T13:34:27Z")

</div>

**[mariojmartin](https://sourceforge.net/u/mariojmartin/)** wrote on [Tuesday, May 10, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/463e0518/#b0fa):

I am using glfw-2.7 on a Windows XP sp3. The graphic card is an Nvidia 6600,  
compatible up to GL 2.0

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 10, 2011, 1:38pm UTC](https://discourse.glfw.org/t/glfwswapbuffers-1282-when-window-is-closed/276/6 "2011-05-10T13:38:00Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Tuesday, May 10, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/463e0518/#1856):

The error is likely due to the fact that you’re calling glGetError after the  
context has been destroyed.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 10, 2011, 4:52pm UTC](https://discourse.glfw.org/t/glfwswapbuffers-1282-when-window-is-closed/276/7 "2011-05-10T16:52:08Z")

</div>

**[mariojmartin](https://sourceforge.net/u/mariojmartin/)** wrote on [Tuesday, May 10, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/463e0518/#ac63):

You may right. If I write  
er = glGetError();  
er = glGetError();  
I still get the same error… Very weird 🙂  
I suppose that glfwSwapBuffers is where the context is destroyed, and there  
any OpenGL error check should be done after that.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 10, 2011, 5:02pm UTC](https://discourse.glfw.org/t/glfwswapbuffers-1282-when-window-is-closed/276/8 "2011-05-10T17:02:22Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Tuesday, May 10, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/463e0518/#49a0):

Yes.

By default, glfwSwapBuffers calls glfwPollEvents after having swapped the  
actual buffers and, also by default, when the user attempts to close the  
window, it just gets closed.

Since GLFW treats the window and context as a unit, the GLFW\_OPENED window  
parameter also indicates whether or not there is a context.
