Skip to content

Native Crash related to Window/Video Capture #186

@axolotl32

Description

@axolotl32

Describe the bug
When using window capturer on a window, the java process will crash (EXCEPTION_ACCESS_VIOLATION) if the window is closed/changes.

When running with verbose log mode, here's what gets printed as soon as the window closes before the exit:

(window_capturer_win_gdi.cc:191): Target window has been closed.
(VideoTrackDesktopSource.cpp:121): Permanent error capturing desktop frame. Stopping track.

There seems to be some sort of race condition during the cleanup of the VideoTrack on the native side. I didn't have a symbol file on hand but I took a debugger to it, the issue seems (quite a big guess here - haven't fully confirmed it) to be when stop() is called, its being called from OnCaptureResult like the log says (Line 121), which is called from VideoTrackDesktopSource::capture() which calls capturer->Start(this);, and capturer->CaptureFrame();. CaptureFrame will call OnCaptureResult so the capturer thread tries to stop itself. The thread starts closing whilst its still executing. Some TLS cleanup happens during closing, according to the disassembly, the address where the crash occurs, it tries to access TLS object at offset 0xC5 ([TLS_pointer + 0xC5]) but TlsGetValue() returns null so [NULL + 0xC5] which causes the access violation (i think).

Also there was some comment in the WebRTC repository about not calling stop on the current thread, I think that might be an issue too (the exception occurs from VideoTrackDesktopThread). see this

To Reproduce
Steps to reproduce the behavior:

  1. Set up a window capture (e.g. with the webrtc-examples)
  2. Connect (via browser or any other peer) to the hosted webrtc video stream (else it wont crash)
  3. Close the window you are capturing.
  4. The process will crash with exit code -1073741819

Expected behavior
Expected behaviour is no crash, clean up happens, a new window source can be selected if need be.

Desktop (please complete the following information):

  • OS: Windows
  • Version: 11 Pro 26100

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions