Win32CaptureSample icon indicating copy to clipboard operation
Win32CaptureSample copied to clipboard

Take Snapshot button crashes the application

Open benschop-it opened this issue 3 years ago • 6 comments

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.

benschop-it avatar Feb 17 '22 12:02 benschop-it

What build/version of Windows do you see this behavior on?

robmikh avatar Feb 17 '22 13:02 robmikh

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.

benschop-it avatar Feb 17 '22 17:02 benschop-it

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.

robmikh avatar Feb 17 '22 22:02 robmikh

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();

zgf avatar Feb 20 '22 02:02 zgf

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.

robmikh avatar Feb 20 '22 20:02 robmikh

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.

benschop-it avatar Feb 21 '22 14:02 benschop-it