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.83k stars 642 forks source link

GLFW_PLATFORM_ERROR on Wayland #1023

Open Luh-code opened 3 days ago

Luh-code commented 3 days ago

Question

Description: When calling org.lwjgl.glfw.GLFW.glfwInit(), false is returned and a GLFW_PLATFORM_ERROR is thrown with it's description stating, that it failed to load libwayland-client.

Any help in resolving this would be greatly appreciated!

Steps To Reproduce:

  1. Use a Linux system on Wayland
  2. Run an application using LWJGL3
  3. Observe the logs

Actual Behavior: A following stack trace is printed and the program exists:

[ Error]    [LWJGL] GLFW_PLATFORM_ERROR error
    Description : Wayland: Failed to load libwayland-client
    Stacktrace  :
        org.lwjgl.glfw.GLFW.glfwInit(GLFW.java:1109)
        org.app.core.GLManager.init(GLManager.java:31)
        org.app.core.scene.SceneTest.main(SceneTest.java:38)

Expected Behavior: GLFW gets initialized and the program keeps running.

Environment:

Additional Context:

// Initialize GLFW if ( !glfwInit() ) // <---- Returns false Logger.logAndThrow("Unable to initialize GLFW", IllegalAccessException.class);

- Here's my `build.gradle`:

import org.gradle.internal.os.OperatingSystem

plugins { id 'java' id 'application' id 'c' }

group = 'org.app' version = '1.0-SNAPSHOT'

project.ext.lwjglVersion = "3.3.4"

switch (OperatingSystem.current()) { case OperatingSystem.FREE_BSD: project.ext.lwjglNatives = "natives-freebsd" break case OperatingSystem.LINUX: project.ext.lwjglNatives = "natives-linux" def osArch = System.getProperty("os.arch") if (osArch.startsWith("arm") || osArch.startsWith("aarch64")) { project.ext.lwjglNatives += osArch.contains("64") || osArch.startsWith("armv8") ? "-arm64" : "-arm32" } else if (osArch.startsWith("ppc")) { project.ext.lwjglNatives += "-ppc64le" } else if (osArch.startsWith("riscv")) { project.ext.lwjglNatives += "-riscv64" } break case OperatingSystem.MAC_OS: project.ext.lwjglNatives = System.getProperty("os.arch").startsWith("aarch64") ? "natives-macos-arm64" : "natives-macos" break case OperatingSystem.WINDOWS: def osArch = System.getProperty("os.arch") project.ext.lwjglNatives = osArch.contains("64") ? "natives-windows${osArch.startsWith("aarch64") ? "-arm64" : ""}" : "natives-windows-x86" break }

repositories { mavenCentral() maven { url "https://raw.githubusercontent.com/kotlin-graphics/mary/master" } }

dependencies { testImplementation platform('org.junit:junit-bom:5.9.1') testImplementation 'org.junit.jupiter:junit-jupiter'

implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")

implementation "org.lwjgl:lwjgl"
implementation "org.lwjgl:lwjgl-assimp"
implementation "org.lwjgl:lwjgl-bgfx"
implementation "org.lwjgl:lwjgl-cuda"
implementation "org.lwjgl:lwjgl-egl"
implementation "org.lwjgl:lwjgl-fmod"
implementation "org.lwjgl:lwjgl-freetype"
implementation "org.lwjgl:lwjgl-glfw"
implementation "org.lwjgl:lwjgl-harfbuzz"
implementation "org.lwjgl:lwjgl-hwloc"
implementation "org.lwjgl:lwjgl-jawt"
implementation "org.lwjgl:lwjgl-jemalloc"
implementation "org.lwjgl:lwjgl-ktx"
implementation "org.lwjgl:lwjgl-libdivide"
implementation "org.lwjgl:lwjgl-llvm"
implementation "org.lwjgl:lwjgl-lmdb"
implementation "org.lwjgl:lwjgl-lz4"
implementation "org.lwjgl:lwjgl-meow"
implementation "org.lwjgl:lwjgl-meshoptimizer"
implementation "org.lwjgl:lwjgl-msdfgen"
implementation "org.lwjgl:lwjgl-nanovg"
implementation "org.lwjgl:lwjgl-nfd"
implementation "org.lwjgl:lwjgl-nuklear"
implementation "org.lwjgl:lwjgl-odbc"
implementation "org.lwjgl:lwjgl-openal"
implementation "org.lwjgl:lwjgl-opencl"
implementation "org.lwjgl:lwjgl-opengl"
implementation "org.lwjgl:lwjgl-opengles"
implementation "org.lwjgl:lwjgl-openvr"
implementation "org.lwjgl:lwjgl-openxr"
implementation "org.lwjgl:lwjgl-opus"
implementation "org.lwjgl:lwjgl-ovr"
implementation "org.lwjgl:lwjgl-par"
implementation "org.lwjgl:lwjgl-remotery"
implementation "org.lwjgl:lwjgl-rpmalloc"
implementation "org.lwjgl:lwjgl-shaderc"
implementation "org.lwjgl:lwjgl-spvc"
implementation "org.lwjgl:lwjgl-sse"
implementation "org.lwjgl:lwjgl-stb"
implementation "org.lwjgl:lwjgl-tinyexr"
implementation "org.lwjgl:lwjgl-tinyfd"
implementation "org.lwjgl:lwjgl-tootle"
implementation "org.lwjgl:lwjgl-vma"
implementation "org.lwjgl:lwjgl-vulkan"
implementation "org.lwjgl:lwjgl-xxhash"
implementation "org.lwjgl:lwjgl-yoga"
implementation "org.lwjgl:lwjgl-zstd"
runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-assimp::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-bgfx::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-freetype::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-harfbuzz::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-hwloc::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-jemalloc::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-ktx::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-libdivide::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-llvm::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-lmdb::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-lz4::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-meow::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-meshoptimizer::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-msdfgen::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-nanovg::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-nfd::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-nuklear::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-openal::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-opengles::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-openvr::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-openxr::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-opus::$lwjglNatives"
//runtimeOnly "org.lwjgl:lwjgl-ovr::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-par::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-remotery::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-rpmalloc::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-shaderc::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-spvc::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-sse::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-stb::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-tinyexr::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-tinyfd::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-tootle::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-vma::$lwjglNatives"
if (lwjglNatives == "natives-macos" || lwjglNatives == "natives-macos-arm64") runtimeOnly "org.lwjgl:lwjgl-vulkan::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-xxhash::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-yoga::$lwjglNatives"
runtimeOnly "org.lwjgl:lwjgl-zstd::$lwjglNatives"

testImplementation("io.github.spair:imgui-java-app:1.86.10")

implementation("kotlin.graphics:glm:0.9.9.1-7")

// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation 'org.apache.commons:commons-lang3:3.0'
implementation 'commons-io:commons-io:2.13.0'
implementation 'kotlin.graphics:unsigned:3.3.32'

// https://mvnrepository.com/artifact/de.javagl/obj
implementation 'de.javagl:obj:0.4.0'

implementation 'org.json:org.json:chargebee-1.0'

// https://mvnrepository.com/artifact/org.apache.commons/commons-collections4
implementation 'org.apache.commons:commons-collections4:4.4'

implementation 'org.xerial:sqlite-jdbc:3.42.0.0'

// https://mvnrepository.com/artifact/org.freedesktop/wayland
implementation("org.freedesktop:wayland:1.4.1")

}

test { useJUnitPlatform() }

- Full example Logs from an application using LWJGL:

Task :SceneTest.main() FAILED [ Info] Logging file at '/para/Projects/leEngine/javaengine/logs/2024-11-22-14-23-25 - 0.log' [ Info] Setting up OpenGL and GLFW... [ Debug] LWJGL Version: 3.3.4+7 [ Error] [LWJGL] GLFW_PLATFORM_ERROR error Description : Wayland: Failed to load libwayland-client Stacktrace : org.lwjgl.glfw.GLFW.glfwInit(GLFW.java:1109) org.app.core.GLManager.init(GLManager.java:31) org.app.core.scene.SceneTest.main(SceneTest.java:38)

[ !Crit] Unable to initialize GLFW Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalAccessException: Unable to initialize GLFW at org.app.utils.Logger.logAndThrow(Logger.java:126) at org.app.utils.Logger.logAndThrow(Logger.java:131) at org.app.core.GLManager.init(GLManager.java:32) at org.app.core.scene.SceneTest.main(SceneTest.java:38) Caused by: java.lang.IllegalAccessException: Unable to initialize GLFW Caused by: java.lang.IllegalAccessException: Unable to initialize GLFW

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
... 3 more

Execution failed for task ':SceneTest.main()'.

Process 'command '/home/luh/.nix-profile/bin/java'' finished with non-zero exit value 1

EDIT: Upgrading to Gradle 8.11.1 and Java 23 did not fix anything

EDIT 2: When setting a hint to use X11, to try and run the application through xwayland (glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);) a similar thing happens:

[ Error]    [LWJGL] GLFW_PLATFORM_ERROR error
    Description : X11: Failed to load Xlib
    Stacktrace  :
        org.lwjgl.glfw.GLFW.glfwInit(GLFW.java:1109)
        org.app.core.GLManager.init(GLManager.java:31)
        org.app.core.scene.SceneTest.main(SceneTest.java:38)
knokko commented 2 days ago

Have you tried what happens if you call glfwInit() in a C application on your machine?