Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes CreateCaptureItemForWindow throws fatal exception #43

Closed
gileli121 opened this issue Sep 28, 2019 · 14 comments
Closed

Sometimes CreateCaptureItemForWindow throws fatal exception #43

gileli121 opened this issue Sep 28, 2019 · 14 comments

Comments

@gileli121
Copy link

gileli121 commented Sep 28, 2019

After few attempts to call this code:

auto activation_factory = winrt::get_activation_factory<winrt::Windows::Graphics::Capture::GraphicsCaptureItem>();
auto interop_factory = activation_factory.as<IGraphicsCaptureItemInterop>();
winrt::Windows::Graphics::Capture::GraphicsCaptureItem item = { nullptr };
interop_factory->CreateForWindow(hwnd, winrt::guid_of<ABI::Windows::Graphics::Capture::IGraphicsCaptureItem>(), reinterpret_cast<void**>(winrt::put_abi(item)));
return item;

I get exception:
image

And my code does not catch it.

It is very random. most of the time it happen after a lot of attempts to create the capture item.

Questions:

  1. What can cause such exception and how to prevent it? Is there a common user mistake that cause this error?
  2. How to handle the error? How to catch the error in case it happned? My code does not catch it. I don't want that the program will crash at the worst case scenario

Thanks.

@robmikh
Copy link
Member

robmikh commented Oct 2, 2019

Do you have a minimal version of the code that reproduces this error? Otherwise, please collect a process dump and we can take a look.

@gileli121
Copy link
Author

How to collect process dump with visual studio 2019?

@robmikh
Copy link
Member

robmikh commented Oct 2, 2019

Once you see the unhandled exception message from your screenshot, go to Debug->Save Dump As. Please make sure you select "Minidump with Heap" when saving.

@gileli121
Copy link
Author

OK, I will do it when it will happen again and upload here the dump.
Thanks

@robmikh
Copy link
Member

robmikh commented Jan 30, 2020

It's been a few months since any activity, so I'm going to close this issue. Please reopen it with the crash dump if you see it again.

@robmikh robmikh closed this as completed Jan 30, 2020
@yjlintw
Copy link

yjlintw commented Jun 19, 2020

Dmp file (Googld Drive)

I'm having the same problem. The dmp file is too big so I put it on google drive. Hope this will help.

@robmikh
Copy link
Member

robmikh commented Jun 19, 2020

Hey @yjlintw, do you have the same symptoms as the above? Looking at the dump, this won't be a failfast and should throw an exception that you should be able to catch. Are you able to do so?

For some reason I'm not able to recognize the error code that triggers the exception, not sure if there's an issue with the dump or there's some other issue going on. Are you able to reliably reproduce this error? Can you share more about the scenario? Is it always with a certain window? All windows? Does it ever succeed?

We may need to get this reproducing locally to make progress.

@yjlintw
Copy link

yjlintw commented Jun 19, 2020

I don't have the try/catch statement initially. After adding that, I'm able to catch it.

It happens when I stop the capture and then start the capture again. It could happen to all windows, but it does not always happens. It happens every now and then.

My originally implementation was resizing the captured window -> stop capture -> start capture. I now resize the texture instead, which I think is a better implementation anyway, and it helps me get around this error.

@glemselenselv
Copy link

I'm sorry to revive this kinda old thread, but I see similar fatal exceptions when I try to capture child windows or dialogs. I haven't read anything in the offical reference about whether the API supports top-level windows only so I wonder if this is even possible.

@robmikh, could you please confirm/deny my assumption?

@robmikh
Copy link
Member

robmikh commented Jul 29, 2020

That is to be expected. Thanks for a calling that out as far as the documentation goes, we should update it. We only support the capture of top level windows.

@EricBallard
Copy link

Just an FYI - I was encountering this issue when trying to capture a window using DirectX 12, in the application settings - after changing to DirectX 11 (Legacy) I was able to capture the window without issue.

@robmikh
Copy link
Member

robmikh commented Aug 4, 2021

Correct, the Direct3D11CaptureFramePool does not support 11-on-12. We need to do some work to support Direct3D 12.

@tianyouhui
Copy link

tianyouhui commented Sep 18, 2023

interop_factory->CreateForWindow() always crash while begin to capture window zoom->settings, is there something wrong?
image

@robmikh
Copy link
Member

robmikh commented Sep 18, 2023

I'm guessing it's because the window is a tool window. The general rule of thumb is that if it's in alt+tab, you should be able to capture it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants