# glfwSetWindowSizeCallback - Error?

**URL:** <https://discourse.glfw.org/t/glfwsetwindowsizecallback-error/306>\
**Category:** support\
**Created:** [August 5, 2010, 7:35pm UTC](https://discourse.glfw.org/t/glfwsetwindowsizecallback-error/306 "2010-08-05T19:35:41Z")\
**Posts on this page:** 5\
**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:** [August 5, 2010, 7:35pm UTC](https://discourse.glfw.org/t/glfwsetwindowsizecallback-error/306/1 "2010-08-05T19:35:41Z")

</div>

**[soulfreezer](https://sourceforge.net/u/soulfreezer/)** wrote on [Thursday, August 05, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/958c7ea8/#90b0):

Hello,

I have problems to understand how the callback in GLFW works. If I use the  
glfwSetWindowSizeCallback-function, my callback-function will be called two  
times?! Is this a bug? Is the first opening of a window detected as  
"resize"-event?

Here is my little code, maybe can someone help me out with this ☹

#include “Run.h”  
#include “FileLogger.h”

FileLogger fileLogger;

void init()  
{  
fileLogger.log(“Calling init()-Method…”);  
fileLogger.log("…");  
fileLogger.log(“init()-Method finished.”);  
}

void GLFWCALL WindowResize( int width, int height )  
{  
fileLogger.log(“Calling WindowResize()-Method…”);  
fileLogger.log("…");  
fileLogger.log(“WindowResize()-Method finished.”);  
}

void renderLoop()  
{  
glClear(GL\_COLOR\_BUFFER\_BIT);  
glfwSwapBuffers();  
}

int main( void )  
{  
int running = GL\_TRUE;  
glfwInit();

if( !glfwOpenWindow( 1024, 768, 32,32,32,32,0,0, GLFW\_WINDOW ) )  
{  
glfwTerminate();  
return 0;  
}

init();

glfwSetWindowSizeCallback( WindowResize );

while( running )  
{  
renderLoop();  
running = !glfwGetKey( GLFW\_KEY\_ESC ) && glfwGetWindowParam(  
GLFW\_OPENED );  
}

glfwTerminate();  
return 0;  
}

Here the Headerfile:

#ifndef RUN\_H\_  
#define RUN\_H\_  
#include \<GL/glfw.h\>  
void GLFWCALL WindowResize( int width, int height );  
void renderLoop();  
void init();  
#endif /\* RUN\_H\_ \*/

In my Logfile I find this strange output:

05.08.2010 21:34:07 Calling init()-Method…  
05.08.2010 21:34:07 …  
05.08.2010 21:34:07 init()-Method finished.  
05.08.2010 21:34:07 Calling WindowResize()-Method…  
05.08.2010 21:34:07 …  
05.08.2010 21:34:07 WindowResize()-Method finished.  
05.08.2010 21:34:07 Calling WindowResize()-Method…  
05.08.2010 21:34:07 …  
05.08.2010 21:34:07 WindowResize()-Method finished.

I am working under Ubuntu 10.04 LTS - Lucid Lynx -

Thanx so much for help

greetz  
soul

---

<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:** [August 5, 2010, 7:42pm UTC](https://discourse.glfw.org/t/glfwsetwindowsizecallback-error/306/2 "2010-08-05T19:42:14Z")

</div>

**[soulfreezer](https://sourceforge.net/u/soulfreezer/)** wrote on [Thursday, August 05, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/958c7ea8/#bfd9):

hmmm…maybe I have an idea……

if I replace this line

if( !glfwOpenWindow( 1024, 768, 32,32,32,32,0,0, GLFW\_WINDOW ) )

with this line:

if( !glfwOpenWindow( 400, 400, 32,32,32,32,0,0, GLFW\_WINDOW ) )

then I get only one resize-Event!

Could it be, that the size of my window is automaticly corrected by ubuntu to  
my desctop-size, which is smaller than the resolution 1024x768! Then, if the  
first opening of the window is countet as resize-event i would get 2 resize  
events at all.

?

---

<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:** [August 5, 2010, 7:55pm UTC](https://discourse.glfw.org/t/glfwsetwindowsizecallback-error/306/3 "2010-08-05T19:55:48Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Thursday, August 05, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/958c7ea8/#e0b8):

Yes, what you wrote in your second entry sounds like a likely reason. However,  
you should assume that the resize callback can be called at any time and not  
count on it being called a specific number of times.

---

<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:** [August 5, 2010, 7:59pm UTC](https://discourse.glfw.org/t/glfwsetwindowsizecallback-error/306/4 "2010-08-05T19:59:03Z")

</div>

**[melekor](https://sourceforge.net/u/melekor/)** wrote on [Thursday, August 05, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/958c7ea8/#513e):

GLFW doesn’t guarantee anything about the number of times your callback is  
invoked. GLFW pretty much just wraps the OS, so chances are if you are seeing  
two resize events then it is because the OS is sending two. In fact, you can  
and will get different results running your code on different OSes and  
different settings. This is to be expected and is not a bug in GLFW.

With regards to your specific case, I suppose you could argue that GLFW should  
be clamping the window size to the desktop size before the window is created,  
since resizing could cause flicker or something like 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:** [August 6, 2010, 11:13am UTC](https://discourse.glfw.org/t/glfwsetwindowsizecallback-error/306/5 "2010-08-06T11:13:46Z")

</div>

**[soulfreezer](https://sourceforge.net/u/soulfreezer/)** wrote on [Friday, August 06, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/958c7ea8/#62ed):

Thanx so much! Now I understand it 😉
