Search code examples
scalalwjglglfwrepeat

LWJGL: Weird behiavour Issue with GLFW Key Callback


I'm using the Scala language. Libraries used are: Akka, LWJGL (includes GLFW)

When testing at high fps, like 4000 for example, everything works as expected. But as I lower the fps to 30 by adding 100k cubes, the key polling of glfw seems to get issues.

When I release a key, the callback gets called instantly with a new key_pressed event, and then a new keyrelease a few seconds later. Please see this video here for a detailled example:https://youtu.be/l2kCWWK44ig

I made sure that there is only 1 callback active, and there is only 1 glPollEvents() call. If that is not weird enough, calling glPollEvents() 20 times per update loops seems to reduce the time between the key release and the second key_released event...

Thanks!


Solution

  • I didn't exactly found what was causing it, but the issue is gone. From what I understood, running glfw and opengl in the same thread on a multithreaded game running at lower than 60 fps causes weird behaviour in the glfw polling internal threading. To fix it, I created a subthread under the main window thread and put a fast ticking loop that calls glfwPollKeys at a faster rate than the window refresh rate. The problem is now gone, at the price of a loop and a thread.