Win32CaptureSample
Win32CaptureSample copied to clipboard
Take Snapshot button crashes the application
I am running the code (Debug X64 both with VS2019 and VS2022), and it crashes when I click on the Take Snapshot button. The crash happens in: auto file = co_await m_savePicker.PickSaveFileAsync(); I've seen people reporting crashes in the FileSavePicker dialog, but the reported tickets have been closed with the advice to Initialize the object with Window handle, which you already do: window.InitializeObjectWithWindowHandle(savePicker); The CapturePicker however does work, but only when indeed you initialize it with the window handle. It seems there is still something wrong with the FileSavePicker.
What build/version of Windows do you see this behavior on?
I am running Version 20H2 (OS Build 19042.1466). The problem only occurs in the C++ Win32 project. In a C++ UWP project it works fine.
Hmmm, my home machine is on a slightly newer build (19043.1526) and I'm unable to reproduce it. I'll see if I can setup a machine with the same build.
I have the same problem when I build x64 and run on win 10.0.119043. crash at auto file = co_await m_savePicker.PickSaveFileAsync();
That's interesting. Could you try attaching a debugger and do the following:
- In
WinMain
, break in and note the thread Id of the UI/main thread. - Just before the line that throws/crashes, break in and check the thread Id of the current thread.
Are they the same? If not, this may be the source of the issue. Try calling co_await m_mainThread
before the line that throws/crashes and see if that fixes it.
I tried what you suggested. Both are the same thread.
In WinMain: Not Flagged > 0x00007898 0x00 Main Thread Main Thread Win32CaptureSample.exe!WinMain
In App.TakeSnapshotAsync: Not Flagged > 0x00007898 0x00 Main Thread Main Thread Win32CaptureSample.exe!App::TakeSnapshotAsync$_ResumeCoro$1
However, the exception is thrown in another thread: Not Flagged > 0x0000A358 0x00 Worker Thread ntdll.dll thread Win32CaptureSample.exe!_CxxThrowException
This thread starts at base.h: inline void __stdcall resume_background_callback(void*, void* context) noexcept { coroutine_handle<>::from_address(context)(); };
Maybe it is expected that this code is running on a different thread, I did not look into the details.