Skip to content

GraphicsCapture Session::Close not responding #138

Open

Description

@PanWesley

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

Image

Activity

  1. robmikh commented on Oct 28, 2024

    @robmikh
    Member

    What build of Windows are you seeing this on? Could you also provide a dump of the capture service?

  2. PanWesley commented on Oct 29, 2024

    @PanWesley
    Author

    What build of Windows are you seeing this on? Could you also provide a dump of the capture service?

    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

  3. PanWesley commented on Nov 4, 2024

    @PanWesley
    Author

    robmikh (@robmikh) do you have any suggestions on this?

    What build of Windows are you seeing this on? Could you also provide a dump of the capture service?

    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

  4. robmikh commented on Nov 5, 2024

    @robmikh
    Member

    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:

    • Open Task Manager
    • Got to the Services tab
    • Find a service with that starts with the name 'CaptureService'
    • Right-click the service and select "Go to details"
    • Right-click the selected svchost process and select "Create memory dump file"

    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.

  5. PanWesley commented on Nov 5, 2024

    @PanWesley
    Author

    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:

    • Open Task Manager
    • Got to the Services tab
    • Find a service with that starts with the name 'CaptureService'
    • Right-click the service and select "Go to details"
    • Right-click the selected svchost process and select "Create memory dump file"

    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.

    Got it. I'll follow this approach next time I reproduce this issue from a user.

  6. PanWesley commented on Nov 25, 2024

    @PanWesley
    Author

    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:

    • Open Task Manager
    • Got to the Services tab
    • Find a service with that starts with the name 'CaptureService'
    • Right-click the service and select "Go to details"
    • Right-click the selected svchost process and select "Create memory dump file"

    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.

    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

  7. robmikh commented on Dec 5, 2024

    @robmikh
    Member

    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.

  8. PanWesley commented on Dec 17, 2024

    @PanWesley
    Author

    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.

    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.).

  9. PanWesley commented on Jun 19, 2025

    @PanWesley
    Author

    Hi, robmikh (@robmikh) Any progress on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions