LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.67k stars 628 forks source link

GL.createCapabilities - java.lang.IllegalStateException: There is no OpenGL context current in the current thread LWJGL 3.3.3 regression #947

Closed dpospisil closed 7 months ago

dpospisil commented 7 months ago

Version

3.3.3

Platform

Linux x64

JDK

OpenJDK 21

Module

OpenGL

Bug description

I am getting IllegalStateException while attaching to GL context in an LWJGL application embeded into a native C++ app (X-Plane). I am getting the error in the following situation:

1) Platform is Linux 2) Machine is dual-gpu (Radeon & NVidia) 3) GL context is Mesa - ZINK powered, created by native app (X-Plane)

The exception is thrown only with LWJGL 3.3.3. With 3.3.2, the above works perfectly fine. The GL context must be valid because other native non LWJGL based plugins work OK.

Anything relevant changed in GL context init in version 3.3.3 which might be causing this?

Stacktrace or crash log output

java.lang.IllegalStateException: There is no OpenGL context current in the current thread.
        at org.lwjgl.opengl.GL.createCapabilities(GL.java:382)
        at org.lwjgl.opengl.GL.createCapabilities(GL.java:311)
        at org.lwjgl.opengl.GL.createCapabilities(GL.java:295)
        at com.airfoillabs.xjet.graphics.GLGraphics.init(GLGraphics.java:1194)
Spasi commented 7 months ago

Hey @dpospisil,

Anything relevant changed in GL context init in version 3.3.3 which might be causing this?

Yes, LWJGL now prefers loading libGLX.so.0 over libGL.so.1 to be compatible with GLFW. See libglvnd for more information. I suspect that this succeeds, but the native application loaded libGL.so.1 instead.

You can verify this by passing these JVM arguments: -Dorg.lwjgl.util.Debug=true -Dorg.lwjgl.util.DebugLoader=true. A workaround would be -Dorg.lwjgl.opengl.libname=libGL.so.1, which overrides the default LWJGL behavior.

dpospisil commented 7 months ago

@Spasi Many thanks for quick response. Closing as this is expected behavior and the workaround -Dorg.lwjgl.opengl.libname=libGL.so.1 works.