Skip to content

[Bug]: macOS window capture always crashes the helper with CGS_REQUIRE_INIT #487

Description

@naadydev

Search existing issues

  • I have searched the existing issues

Describe the bug

On macOS, choosing any window from the Windows tab of the source picker and pressing record kills the capture helper instantly. Nothing is recorded, no file is written, and the HUD returns to idle as if the click never happened — no error is surfaced in the UI.

openscreen-screencapturekit-helper aborts with:

Assertion failed: (did_initialize), function CGS_REQUIRE_INIT, file CGInitialization.c, line 44.

Crash report stack (~/Library/Logs/DiagnosticReports/openscreen-screencapturekit-helper-*.ips), EXC_CRASH (SIGABRT):

libsystem_c.dylib              __assert_rtn
SkyLight                       SLSGetDisplaysWithRect
SkyLight                       SLGetDisplaysWithRect
ScreenCaptureKit               -[SCContentFilter setContentsAndStreamType]
ScreenCaptureKit               -[SCContentFilter initWithDesktopIndependentWindow:]
openscreen-screencapturekit-helper  ScreenCaptureRecorder.start()
openscreen-screencapturekit-helper  specialized static OpenScreenScreenCaptureKitHelper.main()

Cause. The helper is a plain command-line executable (@main struct … { static func main() async }), so nothing in the process ever connects to the window server. SCContentFilter(desktopIndependentWindow:) resolves which display the window sits on by calling into SkyLight, and SkyLight asserts when CoreGraphics was never initialised in the process.

Display capture is unaffected. The two paths diverge in makeCaptureTarget: the display branch builds SCContentFilter(display:excludingWindows:) from an already-resolved display and never asks SkyLight to resolve a rect. Only the window branch does. That asymmetry is presumably why this has gone unreported — full-screen recording, the common path, works fine.

Touching any CoreGraphics display API first performs the initialisation; _ = CGMainDisplayID() at the top of main() is sufficient.

Expected behavior

Selecting a window and recording produces a recording of that window, and the editor opens on it — the same as selecting a screen.

To Reproduce

  1. Open OpenScreen on macOS.
  2. Click the source button → Windows tab → pick any window → Share.
  3. Press record.

The helper aborts during the countdown. Nothing is saved, and a fresh .ips crash report appears in ~/Library/Logs/DiagnosticReports/.

Reproducible from the shell against the shipped helper, with no GUI involved:

REQ='{"schemaVersion":1,"recordingId":1,
  "source":{"type":"window","sourceId":"window:<ID>","windowId":<ID>},
  "video":{"fps":30,"width":1337,"height":842,"hideSystemCursor":false},
  "audio":{"system":{"enabled":false},"microphone":{"enabled":false,"gain":1.0}},
  "webcam":{"enabled":false,"width":0,"height":0,"fps":0},
  "cursor":{"mode":"none"},
  "outputs":{"screenPath":"/tmp/out.mp4"}}'
( sleep 5; echo stop ) | "/Applications/Openscreen.app/Contents/Resources/electron/native/bin/darwin-arm64/openscreen-screencapturekit-helper" "$REQ"
# -> Assertion failed: (did_initialize) ... no /tmp/out.mp4

Swapping in a helper built with _ = CGMainDisplayID() added to main(), same request JSON:

{"event":"ready","schemaVersion":1}
{"event":"recording-started","width":1336,"height":840,...}
{"event":"recording-stopped","screenPath":"/tmp/out.mp4"}
# -> 4.49s / 1336x840, decodes clean

Screenshots

No response

OS

macOS

OS Version

26.6.2 (25G83), Apple Silicon (M1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: fixed in mainWork is merged into main but may not be in a downloadable release yet.status: pending releaseMerged change is waiting for a packaged desktop release.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions