Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLFW_PLATFORM_ERROR on Wayland #1023

Open
Luh-code opened this issue Nov 22, 2024 · 2 comments
Open

GLFW_PLATFORM_ERROR on Wayland #1023

Luh-code opened this issue Nov 22, 2024 · 2 comments

Comments

@Luh-code
Copy link

Luh-code commented Nov 22, 2024

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:

  • OS: NixOS 24.11.20241105.4aa3656 (Vicuna)
  • Kernel: Linux 6.11.5-zen1
  • WM: Hyprland
  • Java Version: 17
  • Hardware:
    • CPU: AMD Ryzen 7 7700
    • GPU: NVIDIA GeForce RTX 3080 LHR

Additional Context:

  • LWJGL Version: 3.3.4
  • Here is the code snippet, that throws:
// Set error callback to Logger::logError
GLFWErrorCallback.createPrint(Logger.getErrorStream()).set();

// 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

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

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
Copy link
Contributor

knokko commented Nov 24, 2024

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

@Spasi
Copy link
Member

Spasi commented Dec 9, 2024

Hey @Luh-code,

I cannot reproduce this, with either the Wayland or X11 backends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants