mirror of
https://github.com/Blinue/Magpie.git
synced 2026-06-24 02:04:10 +00:00
修复GraphicsCapture CRITICAL_SECTION异常
对_newFrameArrived的操作应该放在CRITICAL_SECTION中,Update和_OnFrameArrived为不同线程,此处的赋值会破坏CRITICAL_SECTION,导致_OnFrameArrived函数中LeaveCriticalSection异常
This commit is contained in:
parent
b2fa428903
commit
ce03122532
1 changed files with 8 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue