Skip to content

fix: timing issue DCHECK crash in DesktopCapturer on macOS #51506

Merged
ckerr merged 4 commits into
42-x-yfrom
fixup_desktop_cap_42
May 6, 2026
Merged

fix: timing issue DCHECK crash in DesktopCapturer on macOS #51506
ckerr merged 4 commits into
42-x-yfrom
fixup_desktop_cap_42

Conversation

@jkleinsc

@jkleinsc jkleinsc commented May 5, 2026

Copy link
Copy Markdown
Member

Backport of #50960

See those PR for details.

Notes: Fixed DesktopCapturer crash on macOS.
Fixed desktopCapturer.getSources() hanging on macOS.

ckerr and others added 4 commits May 5, 2026 16:17
refactor: use StartUpdating in desktopCapturer

Replace the one-shot Update() callback model with the continuous
StartUpdating() observer model for NativeDesktopMediaList.

Fixes a macOS DCHECK(can_refresh()) crash in UpdateSourceThumbnail(),
where ScreenCaptureKit's recurrent thumbnail capturer would post
UpdateSourceThumbnail callbacks after the one-shot refresh_callback_
had been consumed. Now, can_refresh() is always true because
refresh_callback_ is repopulated via ScheduleNextRefresh().

Each capturer (window, screen) gets its own ListObserver that tracks
readiness via OnSourceAdded and OnSourceThumbnailChanged events.
Once a list has both sources and thumbnails (or thumbnails aren't
requested), its data is snapshotted and the capturer checks if all
requested types are ready before resolving to JS.

Also remove the "skip_next_refresh_" Chromium patch, which was a
workaround for the timing mismatch between the one-shot Update()
model and ScreenCaptureKit's asynchronous thumbnail delivery.

refactor: simplify state logic in DesktopCapturer
(cherry picked from commit dad4ab6)
* fix: do not block indefinitely on thumbnails in desktopCapturer

fixes dad4ab6 regression

* fix: build error

* fixup! fix: do not block indefinitely on thumbnails in desktopCapturer

chore: remove unnecessary code

* Update shell/browser/api/electron_api_desktop_capturer.cc

Co-authored-by: Niklas Wenzel <dev@nikwen.de>

---------

Co-authored-by: Niklas Wenzel <dev@nikwen.de>
(cherry picked from commit a1d28e6)
fix: dangling raw_ptr in desktopCapturer
(cherry picked from commit bef68b6)
…()` (#51399)

refactor: do not pass a DesktopMediaList* to DesktopCapturer::OnListReady()

The list pointer was being used as a proxy for its type, so just pass
the type instead. This solves a lifecycle issue occurring in CI where
the callack can outlive the DesktopMediaList.

Sample error log:

[48471:0428/193441.269750:FATAL:base/allocator/partition_alloc_support.cc:798] Detected dangling raw_ptr in unretained with id=0x0000013c02e14378:
 Task trace:
 0   Electron Framework  0x000000012283a0ba electron::api::DesktopCapturer::ListObserver::MaybeNotifyReady() + 170
 1   Electron Framework  0x0000000133246dc5 NativeDesktopMediaList::Worker::OnRecurrentCaptureResult(webrtc::DesktopCapturer::Result, std::__Cr::unique_ptr<webrtc::DesktopFrame, std::__Cr::default_delete<webrtc::DesktopFrame>>, long) + 357
 2   Electron Framework  0x000000013328dbcf (anonymous namespace)::ScreenshotManagerCapturer::OnRecurrentCaptureTimer() + 1343
 Stack trace:
 0   Electron Framework  0x000000012ade42f2 base::debug::CollectStackTrace(base::span<void const*, 18446744073709551615ul, void const**>) + 18
 1   Electron Framework  0x000000012add00e1 base::debug::StackTrace::StackTrace(unsigned long) + 225
 2   Electron Framework  0x000000012ade978a base::allocator::UnretainedDanglingRawPtrDetectedCrash(unsigned long) + 90
 3   Electron Framework  0x000000012ae437f7 base::internal::RawPtrBackupRefImpl<true>::ReportIfDanglingInternal(unsigned long) + 391

(cherry picked from commit f8d0412)
@jkleinsc jkleinsc requested a review from a team as a code owner May 5, 2026 20:25
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label May 5, 2026
@trop trop Bot added 42-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes labels May 5, 2026
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label May 5, 2026
@ckerr ckerr merged commit 7db53c0 into 42-x-y May 6, 2026
127 of 130 checks passed
@release-clerk

release-clerk Bot commented May 6, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed DesktopCapturer crash on macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

42-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants