diff --git a/Assets/uWindowCapture/Examples/Desktop Layout/Desktop Layout.unity b/Assets/uWindowCapture/Examples/Desktop Layout/Desktop Layout.unity index 73999e8..021bb68 100644 Binary files a/Assets/uWindowCapture/Examples/Desktop Layout/Desktop Layout.unity and b/Assets/uWindowCapture/Examples/Desktop Layout/Desktop Layout.unity differ diff --git a/Assets/uWindowCapture/Plugins/x86/uWindowCapture.dll b/Assets/uWindowCapture/Plugins/x86/uWindowCapture.dll index d76a650..5992b64 100644 Binary files a/Assets/uWindowCapture/Plugins/x86/uWindowCapture.dll and b/Assets/uWindowCapture/Plugins/x86/uWindowCapture.dll differ diff --git a/Assets/uWindowCapture/Plugins/x86_64/uWindowCapture.dll b/Assets/uWindowCapture/Plugins/x86_64/uWindowCapture.dll index 238e11f..2d213dd 100644 Binary files a/Assets/uWindowCapture/Plugins/x86_64/uWindowCapture.dll and b/Assets/uWindowCapture/Plugins/x86_64/uWindowCapture.dll differ diff --git a/Plugins/uWindowCapture/uWindowCapture/Util.h b/Plugins/uWindowCapture/uWindowCapture/Util.h index 5adc1bd..d561f72 100644 --- a/Plugins/uWindowCapture/uWindowCapture/Util.h +++ b/Plugins/uWindowCapture/uWindowCapture/Util.h @@ -5,7 +5,7 @@ #include #include -#define UWC_DEBUG_ON +// #define UWC_DEBUG_ON // Window utilities diff --git a/Plugins/uWindowCapture/uWindowCapture/WindowsGraphicsCapture.cpp b/Plugins/uWindowCapture/uWindowCapture/WindowsGraphicsCapture.cpp index eb985ea..db38615 100644 --- a/Plugins/uWindowCapture/uWindowCapture/WindowsGraphicsCapture.cpp +++ b/Plugins/uWindowCapture/uWindowCapture/WindowsGraphicsCapture.cpp @@ -145,6 +145,8 @@ void WindowsGraphicsCapture::CreatePoolAndSession() void WindowsGraphicsCapture::DestroySession() { + std::scoped_lock lock(sessionAndPoolMutex_); + if (graphicsCaptureSession_) { graphicsCaptureSession_.Close(); @@ -175,6 +177,8 @@ void WindowsGraphicsCapture::Start() manager->Add(shared_from_this()); } + std::scoped_lock lock(sessionAndPoolMutex_); + CreatePoolAndSession(); if (graphicsCaptureSession_) @@ -240,6 +244,8 @@ void WindowsGraphicsCapture::EnableCursorCapture(bool enabled) return; } + std::scoped_lock lock(sessionAndPoolMutex_); + if (graphicsCaptureSession_) { graphicsCaptureSession_.IsCursorCaptureEnabled(enabled); @@ -253,6 +259,8 @@ WindowsGraphicsCapture::Result WindowsGraphicsCapture::TryGetLatestResult() stopTimer_ = 0.f; + std::scoped_lock lock(sessionAndPoolMutex_); + if (!captureFramePool_) return {}; Direct3D11CaptureFrame frame = nullptr; @@ -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(); diff --git a/Plugins/uWindowCapture/uWindowCapture/WindowsGraphicsCapture.h b/Plugins/uWindowCapture/uWindowCapture/WindowsGraphicsCapture.h index 7d3ff77..c4ef5b3 100644 --- a/Plugins/uWindowCapture/uWindowCapture/WindowsGraphicsCapture.h +++ b/Plugins/uWindowCapture/uWindowCapture/WindowsGraphicsCapture.h @@ -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;