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

[5.0] GLFWException when using Wayland #1452

Closed
dmsch opened this issue May 24, 2022 · 10 comments · Fixed by #1608
Closed

[5.0] GLFWException when using Wayland #1452

dmsch opened this issue May 24, 2022 · 10 comments · Fixed by #1608

Comments

@dmsch
Copy link

dmsch commented May 24, 2022

Description

When the OpenTK application is started in a Wayland environment, a GLFWException is thrown.

Unhandled exception. OpenTK.Windowing.GraphicsLibraryFramework.GLFWException: The GLFW library is not initialized
   at OpenTK.Windowing.Desktop.GLFWProvider.<>c.<.cctor>b__5_0(ErrorCode errorCode, String description)
Aborted (core dumped)

Repro steps

Please provide the steps required to reproduce the problem

  1. Run OpenTK application in a Wayland Environment (eg. Sway), Xwayland is disabled.

Related information

  • OS: Ubuntu 22.04
  • SDL or Native backend (if using OpenTK 3.x): Native Backend
  • What version of OpenTK (Installer, NuGet, Source Code): Nuget, 5.0.0-pre.7
  • What runtime (.NET Framework, CoreCLR, Mono): .NET 6.0
  • Workarounds (if any): Use Xorg

Example:

        static void Main(string[] args)
        {
            var gameSettings = new GameWindowSettings()
            {
                IsMultiThreaded = false, 
                RenderFrequency = 60,
                UpdateFrequency = 60, 
            };

            var windowSettings = new NativeWindowSettings()
            {
                APIVersion = new Version(4, 1),
                WindowBorder = WindowBorder.Hidden
            };
            
            using (var game = new MainWindow(gameSettings, windowSettings))
            {
                game.Run();
            }
        }
@NogginBops
Copy link
Member

What happens if you manually call GLFW.Init() before all of the code?
It could also be the GLFW version used. Can you also check what GLFW.GetVersionString() returns.

You could also try manually downloading the latest OpenTK.redist.glfw package from nuget and see if that fixes anything.

@dmsch
Copy link
Author

dmsch commented May 25, 2022

GLFW Version: 3.3.7 X11 GLX EGL OSMesa clock_gettime evdev shared
GLFW.Init() is executed without exception.

The GLFW Binaries are present (runtimes/linux-x64/native/libglfw.so.3.3).
The same application runs fine in a Xorg server environment.
I also tested with different Wayland compositors (labwc, wayfire), same issue.

The exception is thrown when GLFW.GetPrimaryMonitor() is called by the constructor of NativeWindowSettings.

@PJB3005
Copy link
Member

PJB3005 commented May 25, 2022

GLFW doesn't support switching between Wayland/X11 at runtime, it's hardcompiled into the binary which it uses. Only recommendation I can give is to use Xwayland.

@NogginBops
Copy link
Member

@PJB3005 would this mean if we wanted to support Wayland we would need to distribute another glfw binary? Does .net have a RID for Wayland?

@PJB3005
Copy link
Member

PJB3005 commented May 25, 2022

we would need to distribute another glfw binary?

Yes

Does .net have a RID for Wayland?

No

Your only real solution is to ship both X11 and Wayland versions for Linux, then detect (probably via env var?) at runtime whether Wayland is used and if so use a DllImportResolver to switch between the two. This can only happen once, so if Wayland doesn't work at that point you're deadlocked and won't be able to fallback to X11.

This is still quite fragile for a variety of reasons. Really ideally GLFW would just support both at once but...

@NogginBops NogginBops changed the title GLFWException when using Wayland [5.0] GLFWException when using Wayland Aug 8, 2022
@utkumaden
Copy link
Collaborator

utkumaden commented Aug 19, 2022

(probably via env var?)

$XDG_SESSION_TYPE == wayland or x11

source: this answer on unix stack exchange

@NogginBops
Copy link
Member

Ok so there seems like there is a way to fix this issue.
I'm moving the milestone to 4.7.6 so we can fix it there and then it can get forward merged into 5.0 at some point.

@NogginBops NogginBops modified the milestones: 5.0-pre8, 4.7.6 Oct 26, 2022
@NogginBops
Copy link
Member

Moving this to 4.8.0 as it seems more appropriate for that version.

@NogginBops
Copy link
Member

@dmsch it would be great if you are able to test the PR that I've created that loads Wayland binaries for GLFW.

Though it seems like our implementations of GameWindow and NativeWindow rely on features that Wayland doesn't support, so maybe enabling Xwayland and running OpenTK that way is the way to go.

@NogginBops
Copy link
Member

Merged the PR, feel free to reopen if 4.8.0 doesn't solve this issue. Also see #1612

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

Successfully merging a pull request may close this issue.

4 participants