From 288f8ee42fd96c9b434da0bdee7919bc19022eb1 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 28 Jun 2025 13:48:48 +0200 Subject: [PATCH] fix: Crash on Wayland when glfwTerminate() gets called more than once --- main/gui/source/init/run/native.cpp | 22 ++++++++++------------ main/gui/source/init/splash_window.cpp | 6 ------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/main/gui/source/init/run/native.cpp b/main/gui/source/init/run/native.cpp index 06de3fd6d..60cfa30ab 100644 --- a/main/gui/source/init/run/native.cpp +++ b/main/gui/source/init/run/native.cpp @@ -11,6 +11,12 @@ namespace hex::init { int runImHex() { + // Initialize GLFW + if (!glfwInit()) { + log::fatal("Failed to initialize GLFW!"); + std::abort(); + } + ON_SCOPE_EXIT { glfwTerminate(); }; bool shouldRestart = false; do { @@ -20,6 +26,7 @@ shouldRestart = true; }); + // Splash window { auto splashWindow = initializeImHex(); // Draw the splash window while tasks are running @@ -29,19 +36,10 @@ handleFileOpenRequest(); } + // Main window { - // Initialize GLFW - if (!glfwInit()) { - log::fatal("Failed to initialize GLFW!"); - std::abort(); - } - ON_SCOPE_EXIT { glfwTerminate(); }; - - // Main window - { - Window window; - window.loop(); - } + Window window; + window.loop(); deinitializeImHex(); } diff --git a/main/gui/source/init/splash_window.cpp b/main/gui/source/init/splash_window.cpp index d2a91a500..3e87d6da7 100644 --- a/main/gui/source/init/splash_window.cpp +++ b/main/gui/source/init/splash_window.cpp @@ -425,11 +425,6 @@ namespace hex::init { log::error("GLFW Error [{}] : {}", errorCode, desc); }); - if (!glfwInit()) { - log::fatal("Failed to initialize GLFW!"); - std::exit(EXIT_FAILURE); - } - // Configure used OpenGL version #if defined(OS_MACOS) glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); @@ -585,7 +580,6 @@ namespace hex::init { void WindowSplash::exitGLFW() const { glfwDestroyWindow(m_window); - glfwTerminate(); } void WindowSplash::exitImGui() const {