From 1c4284e44923d7c5a6b361e34efb770e724d0e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 10 Jun 2022 15:45:07 +0200 Subject: [PATCH] Wayland: Fix glfwInit closing stdin on failure If platform initialization failed before either timer fd member had been set to -1 or a valid fd, termination would close stdin. (cherry picked from commit 3bbb41eacc294d3030303eabfd16f66d452e9a72) --- README.md | 1 + src/wl_init.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cac5bc79..b041f2e7 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ information on what to include when reporting a bug. - [Wayland] Bugfix: `glfwSetWindowSize` would resize a full screen window - [Wayland] Bugfix: A window content scale event would be emitted every time the window resized + - [Wayland] Bugfix: If `glfwInit` failed it would close stdin ## Contact diff --git a/src/wl_init.c b/src/wl_init.c index 3bd0db69..25d2cb2f 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -314,6 +314,10 @@ int _glfwPlatformInit(void) long cursorSizeLong; int cursorSize; + // These must be set before any failure checks + _glfw.wl.timerfd = -1; + _glfw.wl.cursorTimerfd = -1; + _glfw.wl.cursor.handle = _glfw_dlopen("libwayland-cursor.so.0"); if (!_glfw.wl.cursor.handle) { @@ -430,7 +434,6 @@ int _glfwPlatformInit(void) _glfwInitTimerPOSIX(); - _glfw.wl.timerfd = -1; if (_glfw.wl.seatVersion >= 4) _glfw.wl.timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);