Jelajahi Sumber

Wayland: Fix segfault when there is no seat

Bug encountered running on a headless instance of Weston.

Fixes #2517
Camilla Löwy 1 tahun lalu
induk
melakukan
3573c5a890
3 mengubah file dengan 9 tambahan dan 6 penghapusan
  1. 1 0
      CONTRIBUTORS.md
  2. 1 0
      README.md
  3. 7 6
      src/wl_init.c

+ 1 - 0
CONTRIBUTORS.md

@@ -48,6 +48,7 @@ video tutorials.
  - Andrew Corrigan
  - Bailey Cosier
  - Noel Cower
+ - James Cowgill
  - CuriouserThing
  - Bill Currie
  - Jason Daly

+ 1 - 0
README.md

@@ -124,6 +124,7 @@ information on what to include when reporting a bug.
  - Added `GLFW_UNLIMITED_MOUSE_BUTTONS` input mode that allows mouse buttons beyond
    the limit of the mouse button tokens to be reported (#2423)
  - [Wayland] Bugfix: The fractional scaling related objects were not destroyed
+ - [Wayland] Bugfix: `glfwInit` would segfault on compositor with no seat (#2517)
  - [Null] Added Vulkan 'window' surface creation via `VK_EXT_headless_surface`
  - [Null] Added EGL context creation on Mesa via `EGL_MESA_platform_surfaceless`
 

+ 7 - 6
src/wl_init.c

@@ -137,6 +137,13 @@ static void registryHandleGlobal(void* userData,
                 wl_registry_bind(registry, name, &wl_seat_interface,
                                  _glfw_min(4, version));
             _glfwAddSeatListenerWayland(_glfw.wl.seat);
+
+            if (wl_seat_get_version(_glfw.wl.seat) >=
+                WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION)
+            {
+                _glfw.wl.keyRepeatTimerfd =
+                    timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
+            }
         }
     }
     else if (strcmp(interface, "wl_data_device_manager") == 0)
@@ -853,12 +860,6 @@ int _glfwInitWayland(void)
         }
     }
 
-    if (wl_seat_get_version(_glfw.wl.seat) >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION)
-    {
-        _glfw.wl.keyRepeatTimerfd =
-            timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
-    }
-
     if (!_glfw.wl.wmBase)
     {
         _glfwInputError(GLFW_PLATFORM_ERROR,