Win32CaptureSample icon indicating copy to clipboard operation
Win32CaptureSample copied to clipboard

Windows 11 22H2 OS build 10.0.22621.2428: CreateCaptureSession(item) does not return and hangs

Open xluogithub opened this issue 2 years ago • 28 comments

Hi Team, In last two/three years, my desktop application has been using CreateCaptureSession(item) for capturing other application window's image. It has been working until Windows 11 OS build 22621.2428 has released recently. My desktop application does Not work on Windows 11 22H2 OS build 10.0.22621.2428, it will hang when try to capture an image of other application window.

My QA team has tested following Win11 OS older builds and my desktop application works on all these older builds: Windows 11 Pro - OS Build: 22621.2283 Windows 11 Pro - OS build : 22621.1928 Windows 11 -- OS build: 22621.457

Also, two/three years ago, I have downloaded Win32CaptureSample zip source codes. Now using that source codes, I created a release build of Win32CapureSampe. When running it on Win 11 OS build 22621.2428, after selecting one application such as Notepad from Windows Dropdown(ComboBox), whole Win32CaptrureSamep hangs.

Is this capturing issue on Win11 OS build 10.0.22621.2428? How to resolve this hanging issue when calling CreateCaptureSession(item)?

Thanks for your help and looking forward to advices/suggestions,

xluogithub avatar Oct 17 '23 16:10 xluogithub

Hmmm, I'm unable to reproduce this on my 22621 machines.

robmikh avatar Oct 17 '23 19:10 robmikh

Thanks, Rob for your quick response. Like what I said this issue exists on Win11 OS build 10.0.22621.2428. The following builds are fine Windows 11 Pro - OS Build: 22621.2283 Windows 11 Pro - OS build : 22621.1928 Windows 11 -- OS build: 22621.457

What is your Windows 11 Build #? You can find this by opening Settings->System->About.

My win11 previous build is OS build: 22621.457 and it works fine. But my customers reported this issue and told me their build is build 10.0.22621.2428. Then I updated my Win 11 22621.457 to 22621.2428. After that, I can see this issue.

xluogithub avatar Oct 17 '23 19:10 xluogithub

Ah sorry, I misread your comment. I thought you were saying all 22621 builds were effected. But all the same, I'm running 22621.2428.

robmikh avatar Oct 17 '23 20:10 robmikh

Thanks, Rob for trying. When you run this Win32CaptureSample app, after selecting one application such as Notepad from Windows Dropdown(ComboBox), Win32CaptrureSample is able to capture an image of Notepad? Does Win32CaptrureSamep hang after capturing? Two/three years ago, I have downloaded Win32CaptureSample zip source codes from this repository. And I continue using that version of source codes. It works fine on 22621.457, 22621.1928, 22621.2283. And I built it with VC2019 compiler. Now kind of getting lost --- that version of Win32CaptureSample does not work on Win 11 OS build 22621.2428.

After updating my OS from 22621.2428 to the latest OS build 23565.1000 (Windows 11 Pro Insider Preview), this Win32CaptureSample app works.

What could be wrong on this specific Win 11 OS build 22621.2428? Why CreateCaptureSession(item) hangs and never return from this API?

Thanks for your help,

xluogithub avatar Oct 17 '23 22:10 xluogithub

No, Win32CaptureSample does not hang for me. I'm able to capture windows and displays, and I'm able to continue interacting with the application.

What's interesting is that it hangs on CreateCaptureSession and not something earlier like creating the GraphicsCaptureItem. Is the capture service running (Task Manager -> Services tab -> CaptureService_*)? If you do a visual-based capture instead of a window or display based capture, does it exhibit the same behavior? I don't have a simpler test on hand, but this repo exercises visual-based capture: https://github.com/robmikh/CaptureAdHocTest I would try running the "alpha" test using the exe built out of that repo. (e.g. CaptureAdhocTest.exe alpha)

If you're comfortable, could you collect a memory dump of the following processes while in the repro state:

  • Win32CaptureSample
  • CaptureService
  • DWM.exe

And attach them to a piece of feedback in the FeedbackHub? Make sure to put it in the category of Desktop Environment -> DWM. Please let me know the title of the feedback so I can fish it out when it shows up in a few days. It also wouldn't hurt to include a link to this issue in the feedback.

The easiest way to collect the memory dumps would be to use the Task Manager, go to the details tab, and right click the process and select "Create dump file". To find the CaptureService's process, find the CaptureService_* entry in the services tab, right click, and select "Go to details". That'll take you to the process in the details tab where you can collect the memory dump.

robmikh avatar Oct 17 '23 23:10 robmikh

Thanks, Rob for your response. Is the capture service running (Task Manager -> Services tab -> CaptureService_*)? Yes, it is still running. Have attached two screenshots. First screenshot shows that capture service is running. Second screenshot shows that win32capturesample app is totally freezing, I can not move this window anymore. captureservice win32capturesampe-freezing

Today I will run your mentioned apps(processes) and collect memory dumps. How to collect memory dump? Thanks,

xluogithub avatar Oct 18 '23 15:10 xluogithub

Please refer to my previous message on collecting a memory dump. In short, you can do it through Task Manager.

robmikh avatar Oct 18 '23 23:10 robmikh

Thanks, Rob for your support. Sorry for taking so long to create a feedback. Because I attached multiple files and then click "Submit" button, nothing happened. Then I realized that I can only attach one file, so zipped all dump files and screenshots in one single zip file. Here is a link for my feedback --- https://aka.ms/AAn4fps Feedback's title --- CaptureService hangs (Win32CaptureSample hangs) on Windows 11 OS build 22621.2428

BTW, I only can duplicate this issue by clicking on "Take Snapshot" button a few times like below: I tested another application "Win32CapureSampe" on Win 11 OS build 22621.2428. After selecting one application such as Notepad from Windows Dropdown(ComboBox), then clicked on "Take Snapshot" button. At the beginning, it worked, then tried a few times to click on "Take Snapshot" button, whole Win32CapureSampe was freezing. Could you try to see if you can reproduce this issue by clicking on "Take Snapshot" button a few times.

I also tried CaptureAdHocTest exe on my computer. Running the "alpha" test Passed without any issues.

I also attached a screenshot when Win32CaptureSample app was freezing, you can see that CaptureService had yellow frame all the time. It tells that capturing has been stuck on somewhere and was not able to finish.

Please let me know if you need additional info to debug this issue. Thanks for your help,

captureservice-running

xluogithub avatar Oct 19 '23 14:10 xluogithub

additional info. Once Win32CaptureSample was hanging, I break it under VC2019, you can see this app was hanging on check_hresult(...CreateCaptureSession) in my below screenshot: check-hresult-onCreateCaptureSession

xluogithub avatar Oct 19 '23 16:10 xluogithub

Hi Rob @robmikh Any update on this issue? My product team wanted to know current status on this issue. Now growing number of my customers can not use my desktop application once they updated win11 OS to the latest win OS "win11 22621.2428". Just for your information, my desktop application has been released two years ago, it still works on Windows 10. And it still works on 22621.457, 22621.1928, 22621.2283. Please let me know current status of this issue and if you need additional information, Thanks again for your help,

xluogithub avatar Oct 20 '23 20:10 xluogithub

Unfortunately, I'm having trouble accessing your feedback. I'll comment here when there's something to report.

robmikh avatar Oct 20 '23 21:10 robmikh

you meant that you can see my feedback: Here is a link for my feedback --- https://aka.ms/AAn4fps Feedback's title --- CaptureService hangs (Win32CaptureSample hangs) on Windows 11 OS build 22621.2428 But you are not able to download memory dump files?

xluogithub avatar Oct 20 '23 21:10 xluogithub

No I meant that I couldn't see your feedback. But another colleague was able to help me access it now. I'll let you know if I find something. Unfortunately, I don't see other reports of this issue and it might be tricky to diagnose without a repro.

robmikh avatar Oct 20 '23 21:10 robmikh

How many instances of the Win32CaptureSample are you running? Are you running other applications that call the capture API at the same time?

robmikh avatar Oct 20 '23 21:10 robmikh

This is what I did --- Tried a few times to click on "Take Snapshot" button, whole Win32CapureSampe was freezing. How about changing Win32CaptureSample app, when selecting Notepad on Windows combobox, do not turn on capturing. Only when clicking on "Take Snapshot" button, start capturing a snapshot.

xluogithub avatar Oct 20 '23 21:10 xluogithub

How many instances of the Win32CaptureSample are you running? When i ran Win32CaptureSample, just ran one instance with VC2019

xluogithub avatar Oct 20 '23 21:10 xluogithub

I think I've found the issue. For now the mitigation is to refrain from using the same GraphicsCaptureItem, and to instead create a new one. The snapshot feature of the sample runs into this because it reuses the GraphicsCaptureItem. This is a bug in the capture service that will need to be fixed.

Thank you for collecting the dumps, they were very useful!

robmikh avatar Oct 20 '23 22:10 robmikh

Great news! Thanks.

Here are some parts of my codes: auto item = m_app->StartCaptureFromWindowHandle(window.WindowHandle); OnCaptureStarted(item, CaptureType::ProgrammaticWindow); QPixmap captureImage = TakeSnapshotBlockingCall(id, title, applicationName);

winrt::GraphicsCaptureItem App::StartCaptureFromWindowHandle(HWND hwnd) { auto item = util::CreateCaptureItemForWindow(hwnd); StartCaptureFromItem(item); return item; }

Does util::CreateCaptureItemForWindow(hwnd) create new item?

Try to find a workaround?

xluogithub avatar Oct 20 '23 22:10 xluogithub

Yes, util::CreateCaptureItemForWindow will create a new GraphicsCaptureItem. Inside your TakeSnapshotBlockingCall function, don't use the cached GraphicsCaptureItem and instead create a new item from the same window handle.

robmikh avatar Oct 20 '23 22:10 robmikh

    auto item = Do not use m_capture->CaptureItem(); --- here we need to create new one from the same window handle?
    auto frame = CaptureSnapshot::TakeAsync(m_device, item, pixelFormat).get();

xluogithub avatar Oct 20 '23 22:10 xluogithub

correct?

xluogithub avatar Oct 20 '23 22:10 xluogithub

Correct

robmikh avatar Oct 20 '23 22:10 robmikh

cool and I will give a try to see if this workaround on my future release build.

xluogithub avatar Oct 20 '23 22:10 xluogithub

Tried the mitigation and now my app works on 22621.2428. Thanks for a quick turn around! My product team ask If Windows team will publish this as a known issue, and if there's a timetable for their fix? We've got a lot of unhappy customers who have current production (my company's) desktop app that has been released two or more years ago. Thanks for your help,

xluogithub avatar Oct 20 '23 23:10 xluogithub

At a minimum the fix has already been checked in for a future release of Windows. I don't have anything I can share at this time about servicing the fix to already released versions, I will be speaking to those folks next week.

robmikh avatar Oct 21 '23 00:10 robmikh

Thanks and really appreciate your help!

xluogithub avatar Oct 21 '23 00:10 xluogithub

Hi Rob @robmikh, could you share the timetable about servicing the fix to already released versions like OS build 10.0.22621.2428? A lot of my customers have that build. Thanks,

xluogithub avatar Oct 23 '23 21:10 xluogithub

I have nothing to at that this time. I will post an update when available.

robmikh avatar Oct 23 '23 21:10 robmikh