From e7028e4b296bdfdb6e484b9a116cd8fe9f66a11d Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 8 Nov 2020 23:14:29 -0800 Subject: [PATCH] Qt: Fix running proxied video if it gets pushed to the main thread --- CHANGES | 1 + src/platform/qt/VideoProxy.cpp | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 74383caa4..2802b7f7f 100644 --- a/CHANGES +++ b/CHANGES @@ -54,6 +54,7 @@ Other fixes: - Qt: Fix static compilation in MinGW (fixes mgba.io/i/1769) - Qt: Fix a race condition in the frame inspector - Qt: Load/save bytes from memory viewer in the order visible (fixes mgba.io/i/1900) + - Qt: Fix running proxied video if it gets pushed to the main thread - SM83: Simplify register pair access on big endian - SM83: Disassemble STOP as one byte Misc: diff --git a/src/platform/qt/VideoProxy.cpp b/src/platform/qt/VideoProxy.cpp index 8a89ea533..3e8549d69 100644 --- a/src/platform/qt/VideoProxy.cpp +++ b/src/platform/qt/VideoProxy.cpp @@ -58,11 +58,16 @@ void VideoProxy::deinit() { bool VideoProxy::writeData(const void* data, size_t length) { while (!RingFIFOWrite(&m_dirtyQueue, data, length)) { - emit dataAvailable(); - m_mutex.lock(); - m_toThreadCond.wakeAll(); - m_fromThreadCond.wait(&m_mutex); - m_mutex.unlock(); + if (QThread::currentThread() == thread()) { + // We're on the main thread + mVideoLoggerRendererRun(&m_logger.d, false); + } else { + emit dataAvailable(); + m_mutex.lock(); + m_toThreadCond.wakeAll(); + m_fromThreadCond.wait(&m_mutex); + m_mutex.unlock(); + } } return true; } @@ -112,9 +117,14 @@ void VideoProxy::unlock() { void VideoProxy::wait() { m_mutex.lock(); while (RingFIFOSize(&m_dirtyQueue)) { - emit dataAvailable(); - m_toThreadCond.wakeAll(); - m_fromThreadCond.wait(&m_mutex, 1); + if (QThread::currentThread() == thread()) { + // We're on the main thread + mVideoLoggerRendererRun(&m_logger.d, false); + } else { + emit dataAvailable(); + m_toThreadCond.wakeAll(); + m_fromThreadCond.wait(&m_mutex, 1); + } } m_mutex.unlock(); }