opentk
opentk copied to clipboard
[5.0] GLFWException when using Wayland
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
- 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();
}
}
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.
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.
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.
@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?
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...
(probably via env var?)
$XDG_SESSION_TYPE == wayland or x11
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.
Moving this to 4.8.0 as it seems more appropriate for that version.
@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.
Merged the PR, feel free to reopen if 4.8.0 doesn't solve this issue. Also see #1612