[SOLVED] Pressing keys "at the same time"

Started by Obsyd, October 10, 2018, 09:45:47

Previous topic - Next topic

Obsyd

Hello everyone!

When I press the W and D keys at the same time on my USB keyboard, sometimes one of the key's GLFW_PRESS callback event is delayed. This also happens with other keys when they are pressed simultaneously. (I mostly use W-D and A-S since I'm making a twin-stick shooter and pressing these keys makes diagonal movement possible for the game)
I tested with vsync and without vsync. I also played around with the glfwPollEvents call frequency and call time (before glfwSwapBuffers after glfwSwapBuffers), but the same happens.
The delayed key's event eventually gets fired off but it looks like it comes when the first GLFW_REPEAT event fires of for it!

Here is what pressing the W and D keys simultaneously looks like.
GLFW_PRESS: 87 Engine Tick: 298
GLFW_PRESS: 68 Engine Tick: 313
GLFW_REPEAT: 68 Engine Tick: 314
GLFW_REPEAT: 68 Engine Tick: 315
GLFW_REPEAT: 68 Engine Tick: 316
GLFW_REPEAT: 68 Engine Tick: 316

That is a 15 frame delay and my engine is configured to run at 30Hz so the delay is around 500ms.

I'm on X11, Fedora 4.18.11-200.fc28.x86_64 with the latest LWJGL nightly. Java: 1.8.0_172

I also commented here: https://github.com/glfw/glfw/issues/1112
I think it might be an LWJGL issue since I built the native GLFW library with a simple test case and the problem does not show there.
Tested my code on windows and there is no issue there, so this might only show on linux.

Thank you for your help!

mudlee

I'm not sure if related, but on centos intellij idea made an announcment somewhere that keypressing in java apps may lag. I cant fins the article, but might be related.


Obsyd

Thank you for your reply!
I tested the project without an IDE and the issue sadly still persists.
Am I understanding you correctly that you are saying that the issue might be caused by running the project from IntelliJ?

Thanks again!

mudlee

Yes, I tought that. It's sad it didn't help.

Quote from: Obsyd on October 10, 2018, 18:29:08
Thank you for your reply!
I tested the project without an IDE and the issue sadly still persists.
Am I understanding you correctly that you are saying that the issue might be caused by running the project from IntelliJ?

Thanks again!

spasi

Sounds like #1112 indeed. It's odd that you cannot reproduce it with a custom GLFW build though. Could you please try:

a) Your GLFW build in your Java engine with -Dorg.lwjgl.glfw.libname=<path_to_libglfw_so>.
b) LWJGL's GLFW build with the native test case.

Does the behavior change in either a or b?

Obsyd

Trying to run with my custom native GLFW build. I'm doing something wrong because my shared library file is over 400KB and LWJGL cannot find any normal GLFW functions.
I simply enabled the shared library building via: option(BUILD_SHARED_LIBS "Build shared libraries" ON) in the GLFW cmake file.

[LWJGL] Version: 3.2.1 build 3
[LWJGL]     OS: Linux v4.18.12-200.fc28.x86_64
[LWJGL]    JRE: 1.8.0_172 amd64
[LWJGL]    JVM: Java HotSpot(TM) 64-Bit Server VM v25.172-b11 by Oracle Corporation
[LWJGL] Loading library (system): lwjgl
[LWJGL]    Loaded from org.lwjgl.librarypath: /home/obsyd/Dokumentumok/Projects/New_Engine_84_68/liblwjgl.so
[LWJGL] Loading library: /home/obsyd/Dokumentumok/Projects/New_Engine_84_68/libglfw.so
[LWJGL] MemoryUtil accessor: MemoryAccessorUnsafe
[LWJGL]    Success
Exception in thread "main" java.lang.ExceptionInInitializerError
   at org.lwjgl.glfw.GLFW.glfwInit(GLFW.java:823)
   at core.GLFW_System.initGLFW(GLFW_System.java:99)
   at core.Boot.boot(Boot.java:56)
   at core.Base.main(Base.java:78)
Caused by: java.lang.NullPointerException: A required function is missing: glfwInitHint
   at org.lwjgl.system.APIUtil.requiredFunctionMissing(APIUtil.java:142)
   at org.lwjgl.system.APIUtil.apiGetFunctionAddress(APIUtil.java:135)
   at org.lwjgl.glfw.GLFW$Functions.<clinit>(GLFW.java:681)

spasi

BUILD_SHARED_LIBS should be enough. It's normal to have a bigger file, LWJGL strips it.

Sounds like you're on the latest branch, which corresponds to GLFW 3.2.1 (August 2016). LWJGL tracks the master branch.

Obsyd

My bad! Pulled the master branch and built the shared library. Now it is 327 KB and my project boots with it.
Got a warning but this should be fine:
[LWJGL] [ERROR] Incompatible Java and native library versions detected.

The same delay happens. When running from intellij and when running from terminal without intellij.

spasi

Does the workaround (comment-out XOpenIM) eliminate the issue for you?

Obsyd

Rebuilded glfw with:
//_glfw.x11.im = XOpenIM(_glfw.x11.display, 0, NULL, NULL);


And all events fire immediately! So the problem is within GLFW!
Thank you for your help guys!