Skip to content

[Bug]: wgc-capture: WriteSample hangs indefinitely on first frame, blocking shutdown #626

@LucaFontanot

Description

@LucaFontanot

Search existing issues

  • I have searched the existing issues

Describe the bug

The native Windows capture process (wgc-capture.exe) hangs after stop is requested and never exits, eventually timing out on the Node.js side after 15 seconds.
The shutdown sequence gets stuck at the video-writer / join-begin stage.
The video writer thread never completed even a single frame write — it was stuck inside encoder.writeFrame() for the entire duration of the recording. No encoder-stage events appear anywhere in the process output, which means the hang occurs before or at the very first std::cout call inside writeFrame.

  • The writeVideoFrames loop holds the outer mutex for the entire duration of encoder.writeFrame(), which includes all D3D staging operations and the sinkWriter_->WriteSample() call.
  • On the first frame, something inside this path blocks indefinitely.
  • Alternatively, the hang may be in MFCreateSinkWriterFromURL's deferred initialization triggered on the first WriteSample call — the MF pipeline sometimes initializes lazily, and this can stall on certain GPU driver/system configurations.
  • Removing MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS did not fix the hang, ruling out hardware H264 encoder initialization as the sole cause.

Expected behavior

After stopping the recording, we should go into the editor. Instead the app hangs then crashes.

To Reproduce

  1. Use the native recorder
  2. Start the recording
  3. Stop the recording
  4. Wait for the timeout

Screenshots

2026-05-20.14-10-37.mp4
  • Note: In the video there is an additional "Windows" button I put to toggle and disable the native recorder as it made the app unusable.

OS

Windows

OS Version

Windows 10

Other OS

No response

Browser

Chrome

Browser Version

No response

Other Browser

No response

Device Type

Desktop

Other Device

No response

Additional context

Nome SO Microsoft Windows 10 Pro
Versione 10.0.19045 Build 19045
Produttore sistema GIGABYTE
Modello sistema G5 MF
Tipo sistema PC basato su x64
Processore 12th Gen Intel(R) Core(TM) i5-12500H, 2500 Mhz, 12 core, 16 processori logici
Memoria fisica installata (RAM) 16,0 GB
Memoria virtuale disponibile 13,0 GB
GPU: Nvidia GeForce RTC 4050 Laptop

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions