From f2112dbadca463fc384942c2050e1f09fa9ad3a3 Mon Sep 17 00:00:00 2001 From: Sour Date: Tue, 11 Feb 2020 22:56:38 -0500 Subject: [PATCH] HD Packs: Fixed crash when loading save states --- Core/SaveStateManager.cpp | 4 +++- Core/VideoDecoder.cpp | 8 ++++++++ Core/stdafx.h | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Core/SaveStateManager.cpp b/Core/SaveStateManager.cpp index 31bb0229..02e26bc0 100644 --- a/Core/SaveStateManager.cpp +++ b/Core/SaveStateManager.cpp @@ -178,7 +178,9 @@ bool SaveStateManager::LoadState(istream &stream, bool hashCheckRequired) #ifndef LIBRETRO vector frameData; if(GetScreenshotData(frameData, stream)) { - _console->GetVideoDecoder()->UpdateFrameSync(frameData.data()); + if(_console->IsPaused()) { + _console->GetVideoDecoder()->UpdateFrameSync(frameData.data()); + } } #endif } diff --git a/Core/VideoDecoder.cpp b/Core/VideoDecoder.cpp index 8954a0e3..ed8433fe 100644 --- a/Core/VideoDecoder.cpp +++ b/Core/VideoDecoder.cpp @@ -163,6 +163,14 @@ void VideoDecoder::UpdateFrameSync(void *ppuOutputBuffer, HdScreenInfo *hdScreen return; } + if(_frameChanged) { + //Last frame isn't done decoding yet - sometimes Signal() introduces a 25-30ms delay + while(_frameChanged) { + //Spin until decode is done + } + //At this point, we are sure that the decode thread is no longer busy + } + _frameNumber = _console->GetFrameCount(); _hdScreenInfo = hdScreenInfo; _ppuOutputBuffer = (uint16_t*)ppuOutputBuffer; diff --git a/Core/stdafx.h b/Core/stdafx.h index a2bb0612..50386d69 100644 --- a/Core/stdafx.h +++ b/Core/stdafx.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include