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]; }