Repository navigation
GraphicsCapture Session::Close not responding #138
Copy link
Copy link
Open
Description
I am using Windows.Graphics.Capture to capture window, but sometimes I encounter the issue of GraphicsCapture Session::Close not responding. I always start window capture, stop, and call back data in the same thread.
Can anyone give me some suggestions to resolve this issue?
Here is my sample code:
winrt::Windows::Graphics::Capture::GraphicsCaptureItem m_captureItem = {nullptr};
winrt::Windows::Graphics::SizeInt32 m_contentSize;
winrt::Windows::Graphics::Capture::GraphicsCaptureSession m_session = {nullptr};
winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool m_framepool = {nullptr};
winrt::Windows::Graphics::Capture::GraphicsCaptureItem::Closed_revoker m_closedtoken;
winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool::FrameArrived_revoker m_frametoken;
BOOL CaptureRT::StartWindowCapture(HWND hWND)
{
try
{
LOG(INFO) << StringPrintf("[CaptureRT] Start Window Capture (0x%08X)", hWND);
HRESULT hRes = S_OK;
if (m_captureApp.m_deviceRT != nullptr && hWND != nullptr)
{
auto interop = winrt::get_activation_factory<winrt::Windows::Graphics::Capture::GraphicsCaptureItem,
IGraphicsCaptureItemInterop>();
hRes = interop->CreateForWindow(hWND, winrt::guid_of<ABI::Windows::Graphics::Capture::IGraphicsCaptureItem>(),
reinterpret_cast<void**>(winrt::put_abi(m_captureItem)));
m_closedtoken = m_captureItem.Closed(winrt::auto_revoke, {this, &CaptureRT::OnClosed});
m_contentSize = m_captureItem.Size();
m_framepool = winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool::Create(
m_captureApp.m_deviceRT, winrt::Windows::Graphics::DirectX::DirectXPixelFormat::B8G8R8A8UIntNormalized, 2,
m_contentSize);
m_session = m_framepool.CreateCaptureSession(m_captureItem);
m_frametoken = m_framepool.FrameArrived(winrt::auto_revoke, {this, &CaptureRT::OnFrameArrived});
m_session.StartCapture();
LOG(INFO) << StringPrintf("[CaptureRT] StartCapture success");
return TRUE;
}
return FALSE;
}
catch (...)
{
LOG(ERROR) << StringPrintf("Failed to Create(Unknown exception)");
}
return FALSE;
}
void CaptureRT::Stop()
{
try
{
m_closedtoken.revoke();
m_frametoken.revoke();
if (m_framepool != nullptr)
m_framepool.Close();
m_framepool = nullptr;
if (m_session != nullptr)
m_session.Close();
m_session = nullptr;
m_contentSize.Width = m_contentSize.Height = 0;
}
catch (...)
{
LOG(ERROR) << "Failed to Destroy(Unknown exception)";
}
}The following is the dump and related call stack on anr thread
issue.dmp
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels

Activity
robmikh commentedon Oct 28, 2024
What build of Windows are you seeing this on? Could you also provide a dump of the capture service?
PanWesley commentedon Oct 29, 2024
Windows System Version: 10.0 Build 19045 (revision: 4894; 64-bit)
My customer can reproduce this issue with a high probability with this windows system version.
I have a full dump, but can't upload it successfully due to the website's limited upload file size. Here is the mini dump for this issue: issue.dmp
PanWesley commentedon Nov 4, 2024
robmikh (@robmikh) do you have any suggestions on this?
robmikh commentedon Nov 5, 2024
You'll need to create an issue in the Feedback Hub app, and then attach a dump to that feedback. Once you've done so, please tell me the title of the feedback and any ID it may show you.
However, could you also collect a dump of a service process? While the repro is ongoing:
That will let me determine why Close isn't responding. The stack you've shown says that Close is waiting for the service to respond.
PanWesley commentedon Nov 5, 2024
Got it. I'll follow this approach next time I reproduce this issue from a user.
PanWesley commentedon Nov 25, 2024
Hi robmikh (@robmikh) I created an issue in Feedback Hub with the title "GraphicsCapture Session::Close api not responding" and here is the share link: https://aka.ms/AAtjd66
robmikh commentedon Dec 5, 2024
Thanks for the memory dumps! It looks like the service received the stop request and processed it... I'm not sure why the COM proxy on the app side hasn't received the response at first glance. And you've only seen this on Windows 10 19045? This will take me some time to untangle.
PanWesley commentedon Dec 17, 2024
According to our monitoring data, 80% of the issues occurred in this version, and very few occurred in other versions (10.0.19044, 10.0.22631, 10.0.18363, etc.).
PanWesley commentedon Jun 19, 2025
Hi, robmikh (@robmikh) Any progress on this issue?