diff --git a/CHANGES b/CHANGES index b5a9ffdcd..286e56790 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,7 @@ Other fixes: - Qt: Fix a handful of edge cases with graphics viewers (fixes mgba.io/i/2827) - Qt: Fix full-buffer rewind - Qt: Fix crash if loading a shader fails + - Qt: Fix black screen when starting with a game (fixes mgba.io/i/2781) - Scripting: Fix receiving packets for client sockets - Scripting: Fix empty receive calls returning unknown error on Windows Misc: diff --git a/src/platform/qt/DisplayGL.cpp b/src/platform/qt/DisplayGL.cpp index 95549b0c8..acc001f9a 100644 --- a/src/platform/qt/DisplayGL.cpp +++ b/src/platform/qt/DisplayGL.cpp @@ -48,6 +48,11 @@ using QOpenGLFunctions_Baseline = QOpenGLFunctions_3_2_Core; using namespace QGBA; +enum ThreadStartFrom { + START = 1, + PROXY = 2, +}; + QHash DisplayGL::s_supports; uint qHash(const QSurfaceFormat& format, uint seed) { @@ -235,7 +240,16 @@ void DisplayGL::startDrawing(std::shared_ptr controller) { messagePainter()->resize(size(), devicePixelRatio()); #endif - CoreController::Interrupter interrupter(controller); + startThread(ThreadStartFrom::START); +} + +void DisplayGL::startThread(int from) { + m_threadStartPending |= from; + if (m_threadStartPending < 3) { + return; + } + + CoreController::Interrupter interrupter(m_context); QMetaObject::invokeMethod(m_painter.get(), "start"); if (!m_gl) { if (shouldDisableUpdates()) { @@ -310,6 +324,7 @@ void DisplayGL::stopDrawing() { hide(); } setUpdatesEnabled(true); + m_threadStartPending &= ~1; } m_context.reset(); } @@ -435,6 +450,7 @@ void DisplayGL::setupProxyThread() { #if defined(_WIN32) && defined(USE_EPOXY) epoxy_handle_external_wglMakeCurrent(); #endif + QMetaObject::invokeMethod(this, "startThread", Q_ARG(int, ThreadStartFrom::PROXY)); }); connect(m_painter.get(), &PainterGL::texSwapped, m_proxyContext.get(), [this]() { if (!m_context->hardwareAccelerated()) { diff --git a/src/platform/qt/DisplayGL.h b/src/platform/qt/DisplayGL.h index 3ed31a9d8..a0c0c17d4 100644 --- a/src/platform/qt/DisplayGL.h +++ b/src/platform/qt/DisplayGL.h @@ -113,6 +113,7 @@ protected: virtual void resizeEvent(QResizeEvent*) override; private slots: + void startThread(int); void setupProxyThread(); private: @@ -123,6 +124,7 @@ private: bool m_isDrawing = false; bool m_hasStarted = false; + int m_threadStartPending = 0; std::unique_ptr m_painter; QThread m_drawThread; QThread m_proxyThread;