Skip to content

Commit

Permalink
fix freeze bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Apr 30, 2021
1 parent 8e5ae01 commit 7d6c41a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 1 deletion.
Binary file not shown.
Binary file modified Assets/uWindowCapture/Plugins/x86/uWindowCapture.dll
Binary file not shown.
Binary file modified Assets/uWindowCapture/Plugins/x86_64/uWindowCapture.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Plugins/uWindowCapture/uWindowCapture/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <chrono>
#include <Windows.h>

#define UWC_DEBUG_ON
// #define UWC_DEBUG_ON


// Window utilities
Expand Down
10 changes: 10 additions & 0 deletions Plugins/uWindowCapture/uWindowCapture/WindowsGraphicsCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ void WindowsGraphicsCapture::CreatePoolAndSession()

void WindowsGraphicsCapture::DestroySession()
{
std::scoped_lock lock(sessionAndPoolMutex_);

if (graphicsCaptureSession_)
{
graphicsCaptureSession_.Close();
Expand Down Expand Up @@ -175,6 +177,8 @@ void WindowsGraphicsCapture::Start()
manager->Add(shared_from_this());
}

std::scoped_lock lock(sessionAndPoolMutex_);

CreatePoolAndSession();

if (graphicsCaptureSession_)
Expand Down Expand Up @@ -240,6 +244,8 @@ void WindowsGraphicsCapture::EnableCursorCapture(bool enabled)
return;
}

std::scoped_lock lock(sessionAndPoolMutex_);

if (graphicsCaptureSession_)
{
graphicsCaptureSession_.IsCursorCaptureEnabled(enabled);
Expand All @@ -253,6 +259,8 @@ WindowsGraphicsCapture::Result WindowsGraphicsCapture::TryGetLatestResult()

stopTimer_ = 0.f;

std::scoped_lock lock(sessionAndPoolMutex_);

if (!captureFramePool_) return {};

Direct3D11CaptureFrame frame = nullptr;
Expand Down Expand Up @@ -281,6 +289,8 @@ WindowsGraphicsCapture::Result WindowsGraphicsCapture::TryGetLatestResult()

void WindowsGraphicsCapture::ChangePoolSize(int width, int height)
{
std::scoped_lock lock(sessionAndPoolMutex_);

if (!captureFramePool_) return;

const auto& manager = WindowManager::Get().GetWindowsGraphicsCaptureManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class WindowsGraphicsCapture
winrt::Windows::Graphics::SizeInt32 size_ = { 0, 0 };
Callback callback_;
bool isStarted_ = false;
std::mutex sessionAndPoolMutex_;

float stopTimer_ = 0.f;
bool hasStopRequested_ = false;
Expand Down

0 comments on commit 7d6c41a

Please sign in to comment.