From 9d9b0f9c41bc7706bff197e9428b7944a901d027 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Mon, 2 Oct 2023 02:09:13 +0300 Subject: [PATCH] [Qt] Fix deadlock --- src/panda_qt/main_window.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp index 998f711e..b4887454 100644 --- a/src/panda_qt/main_window.cpp +++ b/src/panda_qt/main_window.cpp @@ -40,7 +40,7 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent) 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 - emuThread = std::thread([&]() { + emuThread = std::thread([this]() { const RendererType rendererType = emu->getConfig().rendererType; usingGL = (rendererType == RendererType::OpenGL || rendererType == RendererType::Software || rendererType == RendererType::Null); usingVk = (rendererType == RendererType::Vulkan); @@ -58,12 +58,10 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent) Helpers::panic("Unsupported graphics backend for Qt frontend!"); } - // Enter our emulator main loop emuThreadMainLoop(); }); } -// This is the main loop that the emulator thread runs after being initialized void MainWindow::emuThreadMainLoop() { while (appRunning) { if (needToLoadROM.load()) { @@ -79,7 +77,10 @@ void MainWindow::emuThreadMainLoop() { 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() { @@ -108,13 +109,11 @@ void MainWindow::selectROM() { // Cleanup when the main window closes 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 if (emuThread.joinable()) { emuThread.join(); } - printf("Emu thread joined!\n"); delete emu; delete menuBar;