all repos — mgba @ 67dae057ed4a77f2640364f18146fc3f62b414e1

mGBA Game Boy Advance Emulator

Qt: Fix cancelling pausing before the frame ends
Vicki Pfau vi@endrift.com
Tue, 17 Nov 2020 22:52:44 -0800
commit

67dae057ed4a77f2640364f18146fc3f62b414e1

parent

61f8f1469421b7460848d71b07466962cf681050

3 files changed, 28 insertions(+), 16 deletions(-)

jump to
M CHANGESCHANGES

@@ -59,6 +59,7 @@ - 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 - Qt: Fix game display sometimes disappearing after closing load/save state screen + - Qt: Fix cancelling pausing before the frame ends - SM83: Simplify register pair access on big endian - SM83: Disassemble STOP as one byte Misc:
M src/platform/qt/CoreController.cppsrc/platform/qt/CoreController.cpp

@@ -406,23 +406,25 @@ mCoreThreadReset(&m_threadContext);

} void CoreController::setPaused(bool paused) { - if (paused == isPaused()) { - return; - } + QMutexLocker locker(&m_actionMutex); if (paused) { - addFrameAction([this]() { - mCoreThreadPauseFromThread(&m_threadContext); - }); + if (m_moreFrames < 0) { + m_moreFrames = 1; + } } else { - mCoreThreadUnpause(&m_threadContext); + m_moreFrames = -1; + if (isPaused()) { + mCoreThreadUnpause(&m_threadContext); + } } } void CoreController::frameAdvance() { - addFrameAction([this]() { - mCoreThreadPauseFromThread(&m_threadContext); - }); - setPaused(false); + QMutexLocker locker(&m_actionMutex); + m_moreFrames = 1; + if (isPaused()) { + mCoreThreadUnpause(&m_threadContext); + } } void CoreController::addFrameAction(std::function<void ()> action) {

@@ -947,11 +949,19 @@ QMutexLocker locker(&m_bufferMutex);

memcpy(m_completeBuffer.data(), m_activeBuffer.constData(), width * height * BYTES_PER_PIXEL); } - QMutexLocker locker(&m_actionMutex); - QList<std::function<void ()>> frameActions(m_frameActions); - m_frameActions.clear(); - for (auto& action : frameActions) { - action(); + { + QMutexLocker locker(&m_actionMutex); + QList<std::function<void ()>> frameActions(m_frameActions); + m_frameActions.clear(); + for (auto& action : frameActions) { + action(); + } + if (m_moreFrames > 0) { + --m_moreFrames; + if (!m_moreFrames) { + mCoreThreadPauseFromThread(&m_threadContext); + } + } } updateKeys();
M src/platform/qt/CoreController.hsrc/platform/qt/CoreController.h

@@ -213,6 +213,7 @@

QList<std::function<void()>> m_resetActions; QList<std::function<void()>> m_frameActions; QMutex m_actionMutex{QMutex::Recursive}; + int m_moreFrames = -1; QMutex m_bufferMutex; int m_activeKeys = 0;