Skip to content

Commit 7d6c41a

Browse files
committed
fix freeze bug.
1 parent 8e5ae01 commit 7d6c41a

File tree

6 files changed

+12
-1
lines changed

6 files changed

+12
-1
lines changed
Binary file not shown.
-14 KB
Binary file not shown.
-19.5 KB
Binary file not shown.

Plugins/uWindowCapture/uWindowCapture/Util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <chrono>
66
#include <Windows.h>
77

8-
#define UWC_DEBUG_ON
8+
// #define UWC_DEBUG_ON
99

1010

1111
// Window utilities

Plugins/uWindowCapture/uWindowCapture/WindowsGraphicsCapture.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ void WindowsGraphicsCapture::CreatePoolAndSession()
145145

146146
void WindowsGraphicsCapture::DestroySession()
147147
{
148+
std::scoped_lock lock(sessionAndPoolMutex_);
149+
148150
if (graphicsCaptureSession_)
149151
{
150152
graphicsCaptureSession_.Close();
@@ -175,6 +177,8 @@ void WindowsGraphicsCapture::Start()
175177
manager->Add(shared_from_this());
176178
}
177179

180+
std::scoped_lock lock(sessionAndPoolMutex_);
181+
178182
CreatePoolAndSession();
179183

180184
if (graphicsCaptureSession_)
@@ -240,6 +244,8 @@ void WindowsGraphicsCapture::EnableCursorCapture(bool enabled)
240244
return;
241245
}
242246

247+
std::scoped_lock lock(sessionAndPoolMutex_);
248+
243249
if (graphicsCaptureSession_)
244250
{
245251
graphicsCaptureSession_.IsCursorCaptureEnabled(enabled);
@@ -253,6 +259,8 @@ WindowsGraphicsCapture::Result WindowsGraphicsCapture::TryGetLatestResult()
253259

254260
stopTimer_ = 0.f;
255261

262+
std::scoped_lock lock(sessionAndPoolMutex_);
263+
256264
if (!captureFramePool_) return {};
257265

258266
Direct3D11CaptureFrame frame = nullptr;
@@ -281,6 +289,8 @@ WindowsGraphicsCapture::Result WindowsGraphicsCapture::TryGetLatestResult()
281289

282290
void WindowsGraphicsCapture::ChangePoolSize(int width, int height)
283291
{
292+
std::scoped_lock lock(sessionAndPoolMutex_);
293+
284294
if (!captureFramePool_) return;
285295

286296
const auto& manager = WindowManager::Get().GetWindowsGraphicsCaptureManager();

Plugins/uWindowCapture/uWindowCapture/WindowsGraphicsCapture.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class WindowsGraphicsCapture
6060
winrt::Windows::Graphics::SizeInt32 size_ = { 0, 0 };
6161
Callback callback_;
6262
bool isStarted_ = false;
63+
std::mutex sessionAndPoolMutex_;
6364

6465
float stopTimer_ = 0.f;
6566
bool hasStopRequested_ = false;

0 commit comments

Comments
 (0)