ImGui cleanup order: prevent error on exit by performing ImGui::SFML::Shutdown() before window close

This commit is contained in:
John McCardle 2026-01-04 16:34:47 -05:00
commit 016ca693b5

View file

@ -124,16 +124,18 @@ void GameEngine::cleanup()
McRFPy_API::game = nullptr; 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) { if (imguiInitialized) {
ImGui::SFML::Shutdown(); ImGui::SFML::Shutdown();
imguiInitialized = false; imguiInitialized = false;
} }
// Force close the window if it's still open
if (window && window->isOpen()) {
window->close();
}
} }
Scene* GameEngine::currentScene() { return scenes[scene]; } Scene* GameEngine::currentScene() { return scenes[scene]; }