Skip to content

Commit

Permalink
Prevent deadlock when breakpoints are hit during main window exit
Browse files Browse the repository at this point in the history
  • Loading branch information
calc84maniac committed Sep 3, 2024
1 parent 4f2c6f1 commit 581998c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions gui/qt/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ void MainWindow::debugExecute(uint32_t offset, uint8_t cmd) {

void MainWindow::debugCommand(int reason, uint32_t data) {
if (!guiEmuValid) {
emu.resume();
return;
}

Expand Down
8 changes: 7 additions & 1 deletion gui/qt/emuthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "capture/animated-png.h"

#include <QtCore/QVector>
#include <QtCore/QEventLoop>
#include <QtCore/QTimer>

#include <cassert>
#include <cstdarg>
Expand Down Expand Up @@ -396,11 +398,15 @@ void EmuThread::load(emu_data_t fileType, const QString &filePath) {
}

void EmuThread::stop() {
// Need to run events to allow queued slots to be processed during exit
QEventLoop eventLoop;
connect(this, &QThread::finished, &eventLoop, [&]() { eventLoop.exit(0); });
if (!isRunning()) {
return;
}
emu_exit();
if (!wait(500)) {
QTimer::singleShot(500, &eventLoop, [&]() { eventLoop.exit(1); });
if (eventLoop.exec()) {
terminate();
wait(500);
}
Expand Down
3 changes: 2 additions & 1 deletion gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,8 @@ void MainWindow::emuSaved(bool success) {
}

void MainWindow::closeEvent(QCloseEvent *e) {
guiEmuValid = false;

if (!m_shutdown) {
m_shutdown = true;

Expand Down Expand Up @@ -1422,7 +1424,6 @@ void MainWindow::closeEvent(QCloseEvent *e) {
}
}

guiEmuValid = false;
emu.stop();
QMainWindow::closeEvent(e);
}
Expand Down

0 comments on commit 581998c

Please sign in to comment.