From 016ca693b5b5076777f5fcdd74ebc36215f4e586 Mon Sep 17 00:00:00 2001 From: John McCardle Date: Sun, 4 Jan 2026 16:34:47 -0500 Subject: [PATCH] ImGui cleanup order: prevent error on exit by performing ImGui::SFML::Shutdown() before window close --- src/GameEngine.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/GameEngine.cpp b/src/GameEngine.cpp index b6f5eb3..ab86bab 100644 --- a/src/GameEngine.cpp +++ b/src/GameEngine.cpp @@ -124,16 +124,18 @@ void GameEngine::cleanup() McRFPy_API::game = nullptr; } - // Shutdown ImGui before closing window + // Close window FIRST - ImGui-SFML requires window to be closed before Shutdown() + // because Shutdown() destroys sf::Cursor objects that the window may reference. + // See: modules/imgui-sfml/README.md - "Call ImGui::SFML::Shutdown() after window.close()" + if (window && window->isOpen()) { + window->close(); + } + + // Shutdown ImGui AFTER window is closed to avoid X11 BadCursor errors if (imguiInitialized) { ImGui::SFML::Shutdown(); imguiInitialized = false; } - - // Force close the window if it's still open - if (window && window->isOpen()) { - window->close(); - } } Scene* GameEngine::currentScene() { return scenes[scene]; }