glfwPollEvents exits function

Using GLFW
Anonymous
2012-09-19
2012-11-08

  • Anonymous
    2012-09-19

    I recently noticed that a call to glfwPollEvents (or glfwWaitEvents)
    immediately exits the containing function. Consider this example:

    bool event_loop(void) {
      glfwPollEvents();
      update(); // Never gets called...
      return true;
    }
    int main() {
      // Initialization...
      while(event_loop()) {
        render();
        glfwSwapBuffers();
      }
      // Termination...
    }
    

    Now when I structure my code like this the window freezes because the update
    and render functions are never called. I'm fairly new to GLFW, so my question
    is if this is the intended behavior or there is something wrong with my code?
    I'm using GLFW from the SVN trunk as a static library under Visual Studio
    2012.

     
  • Camilla Löwy
    Camilla Löwy
    2012-09-19

    It's not intended behaviour and shouldn't even be possible behaviour.

     
  • Camilla Löwy
    Camilla Löwy
    2012-09-19

    The problem is likely in your code or the compiler settings.

     

  • Anonymous
    2012-09-19

    It was a bug in my code. The problem was related to my callback settings. I
    registered a callback with glfwSetWindowRefreshCallback which also called
    glfwSwapBuffers. Every time I polled events the refresh callback got called
    and therefore creating an infinite loop. I guess I have to restructure my code
    a bit…

    One more question: In case the refresh callback calls glfwSwapBuffers is it
    recommended to disable GLFW_AUTO_POLL_EVENTS?

    Thanks alot for your help!

     

  • Anonymous
    2012-09-19

    Just found the answer in the docs:

    When GLFW_AUTO_POLL_EVENTS is disabled, calling glfwSwapBuffers will not
    result in a call to glfwPollEvents. This can be useful if for example
    glfwSwapBuffers needs to be called from within a callback function, since
    calling glfwPollEvents from a callback function is not allowed.

    Thanks again!

     
  • Camilla Löwy
    Camilla Löwy
    2012-09-19

    Glad it works now and thank you for the detailed follow-up!