From 19b69bbdc23a58a97faf88f0fff591b958dffef4 Mon Sep 17 00:00:00 2001 From: Jonian Guveli Date: Thu, 25 Jul 2024 11:04:57 +0300 Subject: [PATCH 1/2] Qt: Stop emuThread on closeEvent --- include/panda_qt/main_window.hpp | 1 + src/panda_qt/main_window.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/panda_qt/main_window.hpp b/include/panda_qt/main_window.hpp index c99fb4c2..ecdbc02e 100644 --- a/include/panda_qt/main_window.hpp +++ b/include/panda_qt/main_window.hpp @@ -139,6 +139,7 @@ class MainWindow : public QMainWindow { MainWindow(QApplication* app, QWidget* parent = nullptr); ~MainWindow(); + void closeEvent(QCloseEvent *event) override; void keyPressEvent(QKeyEvent* event) override; void keyReleaseEvent(QKeyEvent* event) override; void mousePressEvent(QMouseEvent* event) override; diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp index 1f9b8123..284e88ea 100644 --- a/src/panda_qt/main_window.cpp +++ b/src/panda_qt/main_window.cpp @@ -204,14 +204,19 @@ void MainWindow::selectLuaFile() { } } -// Cleanup when the main window closes -MainWindow::~MainWindow() { +// Stop emulator thread when the main window closes +void MainWindow::closeEvent(QCloseEvent *event) { appRunning = false; // Set our running atomic to false in order to make the emulator thread stop, and join it if (emuThread.joinable()) { emuThread.join(); } + SDL_Quit(); +} + +// Cleanup when the main window closes +MainWindow::~MainWindow() { delete emu; delete menuBar; delete aboutWindow; From da23ec1a0683e2317a247a2eb3e5577a1d10c0b5 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:40:01 +0300 Subject: [PATCH 2/2] Don't deinit SDL from non-SDL thread --- src/panda_qt/main_window.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp index 284e88ea..65769116 100644 --- a/src/panda_qt/main_window.cpp +++ b/src/panda_qt/main_window.cpp @@ -211,8 +211,6 @@ void MainWindow::closeEvent(QCloseEvent *event) { if (emuThread.joinable()) { emuThread.join(); } - - SDL_Quit(); } // Cleanup when the main window closes @@ -602,4 +600,4 @@ void MainWindow::pollControllers() { } } } -} \ No newline at end of file +}