diff --git a/mupen64plus-gui/mainwindow.cpp b/mupen64plus-gui/mainwindow.cpp index 106165d..2b730ab 100644 --- a/mupen64plus-gui/mainwindow.cpp +++ b/mupen64plus-gui/mainwindow.cpp @@ -440,6 +440,7 @@ void MainWindow::volumeValueChanged(int value) if (value != settings->value("volume").toInt()) { settings->setValue("volume", value); + settings->sync(); (*CoreDoCommand)(M64CMD_CORE_STATE_SET, M64CORE_AUDIO_VOLUME, &value); } } @@ -997,3 +998,13 @@ m64p_dynlib_handle MainWindow::getCoreLib() { return coreLib; } + +QThread* MainWindow::getRenderingThread() +{ + return rendering_thread; +} + +void MainWindow::setRenderingThread(QThread* thread) +{ + rendering_thread = thread; +} diff --git a/mupen64plus-gui/mainwindow.h b/mupen64plus-gui/mainwindow.h index 0175a28..1f72707 100644 --- a/mupen64plus-gui/mainwindow.h +++ b/mupen64plus-gui/mainwindow.h @@ -43,6 +43,8 @@ public: int getGLES(); void updatePlugins(); void resetCore(); + QThread *getRenderingThread(); + void setRenderingThread(QThread* thread); m64p_dynlib_handle getCoreLib(); explicit MainWindow(QWidget *parent = 0); ~MainWindow(); @@ -127,6 +129,7 @@ private: QString m_title; OGLWindow *my_window = nullptr; + QThread *rendering_thread = nullptr; WorkerThread *workerThread = nullptr; LogViewer logViewer; QSettings *settings = nullptr; diff --git a/mupen64plus-gui/oglwindow.cpp b/mupen64plus-gui/oglwindow.cpp index 94d8106..43b7cbb 100644 --- a/mupen64plus-gui/oglwindow.cpp +++ b/mupen64plus-gui/oglwindow.cpp @@ -3,11 +3,9 @@ #include "mainwindow.h" #include "interface/core_commands.h" -extern QThread* rendering_thread; - void OGLWindow::initializeGL() { doneCurrent(); - context()->moveToThread(rendering_thread); + context()->moveToThread(w->getRenderingThread()); } void OGLWindow::resizeEvent(QResizeEvent *event) { diff --git a/mupen64plus-gui/vidext.cpp b/mupen64plus-gui/vidext.cpp index 315c5aa..a68a47f 100644 --- a/mupen64plus-gui/vidext.cpp +++ b/mupen64plus-gui/vidext.cpp @@ -11,7 +11,6 @@ static int init; static int needs_toggle; static int set_volume; static QSurfaceFormat format; -QThread* rendering_thread; m64p_error qtVidExtFuncInit(void) { @@ -26,7 +25,7 @@ m64p_error qtVidExtFuncInit(void) if (w->getGLES()) format.setRenderableType(QSurfaceFormat::OpenGLES); - rendering_thread = QThread::currentThread(); + w->setRenderingThread(QThread::currentThread()); return M64ERR_SUCCESS; } @@ -34,11 +33,9 @@ m64p_error qtVidExtFuncQuit(void) { init = 0; w->getWorkerThread()->toggleFS(M64VIDEO_WINDOWED); - if (w->getOGLWindow() != nullptr) { - w->getOGLWindow()->doneCurrent(); - w->getOGLWindow()->context()->moveToThread(QApplication::instance()->thread()); - w->getWorkerThread()->deleteOGLWindow(); - } + w->getOGLWindow()->doneCurrent(); + w->getOGLWindow()->context()->moveToThread(QApplication::instance()->thread()); + w->getWorkerThread()->deleteOGLWindow(); return M64ERR_SUCCESS; } @@ -62,7 +59,7 @@ m64p_error qtVidExtFuncSetMode(int Width, int Height, int, int ScreenMode, int) if (!init) { w->getWorkerThread()->createOGLWindow(&format); while (!w->getOGLWindow()->isValid()) {} - while (w->getOGLWindow()->context()->thread() != rendering_thread) {} + while (w->getOGLWindow()->context()->thread() != w->getRenderingThread()) {} w->getWorkerThread()->resizeMainWindow(Width, Height); w->getOGLWindow()->makeCurrent(); init = 1; @@ -207,7 +204,8 @@ m64p_error qtVidExtFuncGLSwapBuf(void) int value; (*CoreDoCommand)(M64CMD_CORE_STATE_QUERY, M64CORE_EMU_STATE, &value); if (value == M64EMU_RUNNING) { - int volume = w->getSettings()->value("volume").toInt(); + QSettings settings(w->getSettings()->fileName(), QSettings::IniFormat); + int volume = settings.value("volume").toInt(); (*CoreDoCommand)(M64CMD_CORE_STATE_SET, M64CORE_AUDIO_VOLUME, &volume); set_volume = 0; } @@ -222,7 +220,7 @@ m64p_error qtVidExtFuncGLSwapBuf(void) } } - if (QThread::currentThread() == rendering_thread) { + if (QThread::currentThread() == w->getRenderingThread()) { w->getOGLWindow()->context()->swapBuffers(w->getOGLWindow()); w->getOGLWindow()->context()->makeCurrent(w->getOGLWindow()); }