修复GraphicsCapture CRITICAL_SECTION异常

对_newFrameArrived的操作应该放在CRITICAL_SECTION中,Update和_OnFrameArrived为不同线程,此处的赋值会破坏CRITICAL_SECTION,导致_OnFrameArrived函数中LeaveCriticalSection异常
This commit is contained in:
GamePPYi 2022-03-03 14:56:56 +08:00
commit ce03122532

View file

@ -153,21 +153,27 @@ bool GraphicsCaptureFrameSource::Initialize() {
FrameSourceBase::UpdateState GraphicsCaptureFrameSource::Update() {
// 每次睡眠 1 毫秒等待新帧到达,防止 CPU 占用过高
BOOL update = FALSE;
EnterCriticalSection(&_cs);
if (!_newFrameArrived) {
SleepConditionVariableCS(&_cv, &_cs, 1);
}
LeaveCriticalSection(&_cs);
if (_newFrameArrived) {
_newFrameArrived = false;
update = TRUE;
}
LeaveCriticalSection(&_cs);
if (update) {
winrt::Direct3D11CaptureFrame frame = _captureFramePool.TryGetNextFrame();
if (!frame) {
// 缓冲池没有帧,不应发生此情况
assert(false);
return UpdateState::Waiting;
}