# GLFW.glfwPollEvents() freezes on Mac

**URL:** <https://discourse.glfw.org/t/glfw-glfwpollevents-freezes-on-mac/1106>\
**Category:** support\
**Created:** [April 20, 2018, 4:35pm UTC](https://discourse.glfw.org/t/glfw-glfwpollevents-freezes-on-mac/1106 "2018-04-20T16:35:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![IndiePig](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/indiepig/32/103_2.png) [@IndiePig](https://discourse.glfw.org/u/IndiePig)\
**Post date:** [April 20, 2018, 4:35pm UTC](https://discourse.glfw.org/t/glfw-glfwpollevents-freezes-on-mac/1106/1 "2018-04-20T16:35:58Z")

</div>

I’m using LWJGL 3.1.6, and on the mac, GLFW freezes on glfwPollEvents(). The LWJGL HelloWorld example seems to work fine, and I don’t think my application is doing anything very different from that example. I’ve tried removing all my callback handlers with no luck.  
It works on Windows. Does anybody have any tips for debugging this? Perhaps gotchas I should look for that could cause glfwPollEvents to hang?

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 20, 2018, 5:07pm UTC](https://discourse.glfw.org/t/glfw-glfwpollevents-freezes-on-mac/1106/2 "2018-04-20T17:07:21Z")

</div>

One thing to check [as noted in the docs for glfwPollEvents](http://www.glfw.org/docs/latest/group__window.html#ga37bd57223967b4211d60ca1a0bf3c832) is to ensure you are calling this from the main thread and not in a callback.

---

<div class="post-metadata">

**Author:** ![IndiePig](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/indiepig/32/103_2.png) [@IndiePig](https://discourse.glfw.org/u/IndiePig)\
**Post date:** [April 20, 2018, 5:48pm UTC](https://discourse.glfw.org/t/glfw-glfwpollevents-freezes-on-mac/1106/3 "2018-04-20T17:48:02Z")

</div>

debugging, it seems like we are on the main thread when it’s called, and it’s definitely not called in a glfw callback.  
We’re adding the VM option: -XstartOnFirstThread

Are there any other vm options we need to consider?

---

<div class="post-metadata">

**Author:** ![IndiePig](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/indiepig/32/103_2.png) [@IndiePig](https://discourse.glfw.org/u/IndiePig)\
**Post date:** [April 20, 2018, 6:30pm UTC](https://discourse.glfw.org/t/glfw-glfwpollevents-freezes-on-mac/1106/4 "2018-04-20T18:30:01Z")

</div>

Ok, that took forever, but I found it!

If I ever call Toolkit.getDefaultToolkit().systemClipboard anywhere, the next poll events would hang (only on Mac).

So I’ve got some studying to do. Anybody have any insights why this is?

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 20, 2018, 8:31pm UTC](https://discourse.glfw.org/t/glfw-glfwpollevents-freezes-on-mac/1106/5 "2018-04-20T20:31:47Z")

</div>

I don’t know enough Java to be familiar with why this would be. Are you able to debug the glfwPollEvents() function C code with XCode at all?

---

<div class="post-metadata">

**Author:** ![michael89](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@michael89](https://discourse.glfw.org/u/michael89)\
**Post date:** [June 2, 2018, 6:12pm UTC](https://discourse.glfw.org/t/glfw-glfwpollevents-freezes-on-mac/1106/6 "2018-06-02T18:12:44Z")

</div>

So I’ve been following the tutorial from [https://vulkan-tutorial.com](https://vulkan-tutorial.com) and have also been noticing my frame rate takes a hit every so often… after timing lots of part of my code thinking it was fence/semaphores related to rendering and trying to work out the cause… it ended up being that PollEvent was taking ~500ms every so often.  
I have some solid repo steps. if you run the code from the end of the tutorial  
[https://vulkan-tutorial.com/Uniform\_buffers/Descriptor\_pool\_and\_sets](https://vulkan-tutorial.com/Uniform_buffers/Descriptor_pool_and_sets).  
When the app is running as long as I move the mouse I’m fine, as soon as I stop ~5secs after is when poll events takes 500ms, it then also normally takes the same on moving the mouse again… So I’m not sure if it’s macOS doing something after 5 seconds of idle that causes glfw to hang or maybe get spammed by so maybe events it take .5 sec, but the 5sec wait and the 0.5 sec poll event are pretty much always the same.

---

<div class="post-metadata">

**Author:** ![michael89](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@michael89](https://discourse.glfw.org/u/michael89)\
**Post date:** [June 2, 2018, 6:18pm UTC](https://discourse.glfw.org/t/glfw-glfwpollevents-freezes-on-mac/1106/7 "2018-06-02T18:18:11Z")

</div>

Actually just after posting this, I realized my keyboard lights are set to turn off after 5 seconds, I changed it to 10 secs, and same repo as above but the freeze happened at 10 secs after moving mouse, so that seems to be the cause, the lights turning off cause poll event to take 500ms (probably the fade duration)?

I’ve submitted a issue on the glfw GitHub

> <https://github.com/glfw/glfw/issues/1283>
