[Qt] Fix deadlock
This commit is contained in:
@@ -40,7 +40,7 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||||||
emu->setOutputSize(screen.surfaceWidth, screen.surfaceHeight);
|
emu->setOutputSize(screen.surfaceWidth, screen.surfaceHeight);
|
||||||
|
|
||||||
// The emulator graphics context for the thread should be initialized in the emulator thread due to how GL contexts work
|
// The emulator graphics context for the thread should be initialized in the emulator thread due to how GL contexts work
|
||||||
emuThread = std::thread([&]() {
|
emuThread = std::thread([this]() {
|
||||||
const RendererType rendererType = emu->getConfig().rendererType;
|
const RendererType rendererType = emu->getConfig().rendererType;
|
||||||
usingGL = (rendererType == RendererType::OpenGL || rendererType == RendererType::Software || rendererType == RendererType::Null);
|
usingGL = (rendererType == RendererType::OpenGL || rendererType == RendererType::Software || rendererType == RendererType::Null);
|
||||||
usingVk = (rendererType == RendererType::Vulkan);
|
usingVk = (rendererType == RendererType::Vulkan);
|
||||||
@@ -58,12 +58,10 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||||||
Helpers::panic("Unsupported graphics backend for Qt frontend!");
|
Helpers::panic("Unsupported graphics backend for Qt frontend!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enter our emulator main loop
|
|
||||||
emuThreadMainLoop();
|
emuThreadMainLoop();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the main loop that the emulator thread runs after being initialized
|
|
||||||
void MainWindow::emuThreadMainLoop() {
|
void MainWindow::emuThreadMainLoop() {
|
||||||
while (appRunning) {
|
while (appRunning) {
|
||||||
if (needToLoadROM.load()) {
|
if (needToLoadROM.load()) {
|
||||||
@@ -79,7 +77,10 @@ void MainWindow::emuThreadMainLoop() {
|
|||||||
swapEmuBuffer();
|
swapEmuBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Emulator thread returned");
|
// Unbind GL context if we're using GL, otherwise some setups seem to be unable to join this thread
|
||||||
|
if (usingGL) {
|
||||||
|
screen.getGLContext()->DoneCurrent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::swapEmuBuffer() {
|
void MainWindow::swapEmuBuffer() {
|
||||||
@@ -108,13 +109,11 @@ void MainWindow::selectROM() {
|
|||||||
|
|
||||||
// Cleanup when the main window closes
|
// Cleanup when the main window closes
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
printf("Destroying window class\n");
|
|
||||||
appRunning = false; // Set our running atomic to false in order to make the emulator thread stop, and join it
|
appRunning = false; // Set our running atomic to false in order to make the emulator thread stop, and join it
|
||||||
|
|
||||||
if (emuThread.joinable()) {
|
if (emuThread.joinable()) {
|
||||||
emuThread.join();
|
emuThread.join();
|
||||||
}
|
}
|
||||||
printf("Emu thread joined!\n");
|
|
||||||
|
|
||||||
delete emu;
|
delete emu;
|
||||||
delete menuBar;
|
delete menuBar;
|
||||||
|
|||||||
Reference in New Issue
Block a user