From cf9ed17134532edc77877712f20d3bdd4ac44257 Mon Sep 17 00:00:00 2001 From: NADY <3747231+naadydev@users.noreply.github.com> Date: Sun, 23 Aug 2026 10:54:52 +0200 Subject: [PATCH] fix: initialise CoreGraphics before building a window capture filter Selecting a window in the source picker aborted the ScreenCaptureKit helper before it produced a single frame: Assertion failed: (did_initialize), function CGS_REQUIRE_INIT, file CGInitialization.c, line 44 The helper is a plain command-line executable, so nothing in it ever connects to the window server. SCContentFilter(desktopIndependentWindow:) resolves which display a window sits on by calling into SkyLight (SLSGetDisplaysWithRect), and SkyLight asserts when CoreGraphics was never initialised in the process. Display capture is unaffected, because SCContentFilter(display:excludingWindows:) is handed an already-resolved display and never asks SkyLight to resolve a rect. That is why only the window branch of makeCaptureTarget crashed. Touching any CoreGraphics display API performs the initialisation, so a single CGMainDisplayID() at the top of main() is enough. CoreGraphics is already imported; this avoids pulling AppKit into the helper or standing up an NSApplication in a CLI process. --- .../ScreenCaptureRecorder.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/electron/native/screencapturekit/Sources/OpenScreenScreenCaptureKitHelper/ScreenCaptureRecorder.swift b/electron/native/screencapturekit/Sources/OpenScreenScreenCaptureKitHelper/ScreenCaptureRecorder.swift index 75163dee7..2e88e5c41 100644 --- a/electron/native/screencapturekit/Sources/OpenScreenScreenCaptureKitHelper/ScreenCaptureRecorder.swift +++ b/electron/native/screencapturekit/Sources/OpenScreenScreenCaptureKitHelper/ScreenCaptureRecorder.swift @@ -802,6 +802,15 @@ final class ScreenCaptureRecorder: NSObject, SCStreamOutput, SCStreamDelegate { struct OpenScreenScreenCaptureKitHelper { static func main() async { do { + // This helper is a plain command-line executable, so nothing has connected it to + // the window server yet. `SCContentFilter(desktopIndependentWindow:)` reaches into + // SkyLight (`SLSGetDisplaysWithRect`) to find the display a window sits on, and + // SkyLight aborts with `CGS_REQUIRE_INIT` when CoreGraphics was never initialised + // in the process — so every window capture crashed before it produced a frame, + // while display capture (which never resolves a rect) worked fine. Touching any + // CoreGraphics display API first performs that initialisation. + _ = CGMainDisplayID() + guard CommandLine.arguments.count == 2 else { throw HelperError.invalidArguments }