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

Wayland: The platform does not provide the window position #393

Closed
gravit0 opened this issue Dec 16, 2023 · 12 comments
Closed

Wayland: The platform does not provide the window position #393

gravit0 opened this issue Dec 16, 2023 · 12 comments
Labels
1.20 Targeted at Minecraft 1.20 bug A bug or error help wanted Extra attention is needed rendering Related to rendering triage Needs triaging and confirmation

Comments

@gravit0
Copy link

gravit0 commented Dec 16, 2023

Minecraft Version: 1.20.2

NeoForge Version: 20.2.86

Logs:

java.lang.IllegalStateException: GLFW error before init: [0x1000C]Wayland: The platform does not provide the window position
	at com.mojang.blaze3d.platform.GLX.lambda$_initGlfw$0(GLX.java:67) ~[client-1.20.2-20231019.002635-srg.jar%23189!/:?] {re:classloading}
	at com.mojang.blaze3d.platform.Window.checkGlfwError(Window.java:129) ~[client-1.20.2-20231019.002635-srg.jar%23189!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at com.mojang.blaze3d.platform.GLX._initGlfw(GLX.java:66) ~[client-1.20.2-20231019.002635-srg.jar%23189!/:?] {re:classloading}
	at com.mojang.blaze3d.systems.RenderSystem.initBackendSystem(RenderSystem.java:559) ~[client-1.20.2-20231019.002635-srg.jar%23189!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.<init>(Minecraft.java:454) ~[client-1.20.2-20231019.002635-srg.jar%23189!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:195) ~[client-1.20.2-20231019.002635-srg.jar%23189!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}
	at net.neoforged.fml.loading.targets.CommonLaunchHandler.runTarget(CommonLaunchHandler.java:126) ~[loader-1.0.16.jar%23172!/:1.0] {}
	at net.neoforged.fml.loading.targets.CommonLaunchHandler.clientService(CommonLaunchHandler.java:114) ~[loader-1.0.16.jar%23172!/:1.0] {}
	at net.neoforged.fml.loading.targets.CommonClientLaunchHandler.runService(CommonClientLaunchHandler.java:24) ~[loader-1.0.16.jar%23172!/:1.0] {}
	at net.neoforged.fml.loading.targets.CommonLaunchHandler.lambda$launchService$4(CommonLaunchHandler.java:108) ~[loader-1.0.16.jar%23172!/:1.0] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.9.jar%23147!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.9.jar%23147!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.9.jar%23147!/:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:108) [modlauncher-10.0.9.jar%23147!/:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:78) [modlauncher-10.0.9.jar%23147!/:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.9.jar%23147!/:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.9.jar%23147!/:?] {}
	at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] {}

Steps to Reproduce:

  1. Use Wayland
  2. Set property -Dorg.lwjgl.glfw.libname=PATH_TO_LIBGLFW_WAYLAND
  3. Run NeoForge

Description of issue:
This error exclusive for Forge. Vanilla and Fabric don't have this error

@gravit0 gravit0 added the triage Needs triaging and confirmation label Dec 16, 2023
@sciwhiz12 sciwhiz12 added bug A bug or error 1.20 Targeted at Minecraft 1.20 rendering Related to rendering labels Dec 23, 2023
@sciwhiz12
Copy link
Member

Some quick searches leads me to PrismLauncher/PrismLauncher#1876, which links to https://github.com/Admicos/minecraft-wayland. According to that repository's README, you may need to disable the early loading window (by setting earlyWindowControl in the FML config file to false) for NeoForge to work properly under Wayland. I suggest you also take a look at the other contents of the repository, since it may be of interest to you.

Someone running Linux and Wayland will have to verify and debug this issue.

@sciwhiz12 sciwhiz12 added the help wanted Extra attention is needed label Dec 23, 2023
@gravit0
Copy link
Author

gravit0 commented Dec 23, 2023

Of course I know about this repository. Unfortunately -Dfml.earlyprogresswindow=false and earlyWindowControl = false did not help

@tmvkrpxl0
Copy link
Contributor

For me, -Dorg.lwjgl.glfw.libname crashes immediately on startup with GLFW issue.
If I disable early progress window, it runs for a bit longer and crashes with other exception, also from GLFW.

@tmvkrpxl0
Copy link
Contributor

Would you like to have my system information as well?

@tmvkrpxl0
Copy link
Contributor

tmvkrpxl0 commented Apr 16, 2024

For me, -Dorg.lwjgl.glfw.libname crashes immediately on startup with GLFW issue. If I disable early progress window, it runs for a bit longer and crashes with other exception, also from GLFW.

Reason for 2nd crash was I had was GLFW I'm using is too old for Minecraft. GLFW that Minecraft uses is 3.4, It is not yet released on my disto yet and I assume same goes for all debian based ones as well since 3.4 is released Feb 24.
so I had to built it locally. For testing I only enabled wayland support. and launched minecraft as described.

It was unable to create window, but after I set __GL_THREADED_OPTIMIZATIONS=0 it launched fine with and without early window control.
I have verified that it is indeed using wayland as program icon was wayland logo instead of x11 logo.
@gravit0 Would you like to check it again?

@tmvkrpxl0
Copy link
Contributor

tmvkrpxl0 commented Apr 16, 2024

Huh I discovered the same problem on 1.20.1
I was initially testing on 1.20.4 so I didn't see the issue.

@tmvkrpxl0
Copy link
Contributor

tmvkrpxl0 commented Apr 16, 2024

On 1.20.1 You need to patch glfw somehow.
Both GLFW 3.3 and 3.4 throw error when application requests window position or changes icon, which are both unavailable on wayland for the moment.
Neoforge requests window position when early window control is enabled.
Minecraft 1.20.1 changes icon.
I think 1.20.4 detects wayland and avoids doing that both because 1.20.4 launched fine for me and the icon was still default wayland logo.

Workaround

You need to build glfw yourself. The patch is not hard. Wayland functions for providing window position and changing icon both look like this:

void _glfwGetWindowPosWayland(_GLFWwindow* window, int* xpos, int* ypos)
{
    // A Wayland client is not aware of its position, so just warn and leave it
    // as (0, 0)

    _glfwInputError(GLFW_FEATURE_UNAVAILABLE,
                    "Wayland: The platform does not provide the window position");
}

It just returns error immediately without doing anything.
As a workaround specifically for Minecraft, we can just change GLFW itself so that it doesn't even return error on those 2 cases.

  1. Clone GLFW
  2. open src/wl_window.c
  3. Delete line that returns _glfwInputError on both _glfwSetWindowIconWayland and _glfwGetWindowPosWayland
  4. create directory build under project root
  5. run cmake -S ./ -B ./build -D GLFW_BUILD_X11=0 -D BUILD_SHARED_LIBS=1.
    • -S ./ sets source of project to current directory, -B ./build sets build directory to ./build which you just created, I disabled X11 support to ensure it actually uses wayland later, and build it as shared library because glfw is built as static library by default.
  6. cd into ./build
  7. run make
    • now there's shared library at glfw/build/src/libglfw.so
  8. launch minecraft with __GL_THREADED_OPTIMIZATIONS=0 environment variable. Since minecraft-launcher was available on terminal for me I could just run __GL_THREADED_OPTIMIZATIONS=0 minecraft-launcher
    • This is crucial because concurrency is different on wayland and minecraft crashes with weird concurrency error.
  9. specify library path with -Dorg.lwjgl.glfw.libname to that file in jvm argument in profile setting

@tmvkrpxl0
Copy link
Contributor

Reason for disabling early window control being suggested is It makes minecraft not even call _glfwGetWindowPosWayland. But if you patch that as well just like I did You can leave it enabled.

@gravit0
Copy link
Author

gravit0 commented Apr 16, 2024

I have no way to test this now, but if you have the version after accepting neoforged/FancyModLoader#68 the problem should go away
You can port this PR to older versions

@tmvkrpxl0
Copy link
Contributor

there still maybe concurrency error (__GL_THREADED_OPTIMIZATIONS=0). I would have to test it myself

@tmvkrpxl0
Copy link
Contributor

Do we still need this? NVIDIA explicit sink is now supported so we can just run it on x11.
Personally x11 experience is better for me now. fcitx5 didn't work on wayland.

@gravit0 gravit0 closed this as completed Jun 16, 2024
@heipiao233
Copy link

heipiao233 commented Jul 1, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.20 Targeted at Minecraft 1.20 bug A bug or error help wanted Extra attention is needed rendering Related to rendering triage Needs triaging and confirmation
Projects
None yet
Development

No branches or pull requests

4 participants