From a96b6229d0dda330e9fe134f9f2f60b22c0e4341 Mon Sep 17 00:00:00 2001 From: Souryo Date: Wed, 6 Jan 2016 20:37:52 -0500 Subject: [PATCH] Fixed multithread crash when loading another game --- Core/VideoDecoder.cpp | 2 ++ Utilities/AutoResetEvent.cpp | 6 ++++++ Utilities/AutoResetEvent.h | 1 + 3 files changed, 9 insertions(+) diff --git a/Core/VideoDecoder.cpp b/Core/VideoDecoder.cpp index 4acd47ec..7b48ab1b 100644 --- a/Core/VideoDecoder.cpp +++ b/Core/VideoDecoder.cpp @@ -135,6 +135,8 @@ void VideoDecoder::StartThread() _stopFlag = false; _frameChanged = false; _frameCount = 0; + _waitForFrame.Reset(); + _waitForRender.Reset(); Instance->_decodeThread.reset(new thread(&VideoDecoder::DecodeThread, Instance.get())); Instance->_renderThread.reset(new thread(&VideoDecoder::RenderThread, Instance.get())); } diff --git a/Utilities/AutoResetEvent.cpp b/Utilities/AutoResetEvent.cpp index 94abd7f1..329bcf82 100644 --- a/Utilities/AutoResetEvent.cpp +++ b/Utilities/AutoResetEvent.cpp @@ -25,6 +25,12 @@ void AutoResetEvent::Wait(int timeoutDelay) _signaled = false; } +void AutoResetEvent::Reset() +{ + std::unique_lock lock(_mutex); + _signaled = false; +} + void AutoResetEvent::Signal() { std::unique_lock lock(_mutex); diff --git a/Utilities/AutoResetEvent.h b/Utilities/AutoResetEvent.h index 0b8bf7b9..b272f1db 100644 --- a/Utilities/AutoResetEvent.h +++ b/Utilities/AutoResetEvent.h @@ -15,6 +15,7 @@ public: AutoResetEvent(); ~AutoResetEvent(); + void Reset(); void Wait(int timeoutDelay = 0); void Signal(); };