fix(mac): re-attach capture on stream death instead of full display rebuild (#29) - #157
Open
kdbhalala wants to merge 1 commit into
Open
fix(mac): re-attach capture on stream death instead of full display rebuild (#29)#157kdbhalala wants to merge 1 commit into
kdbhalala wants to merge 1 commit into
Conversation
…ad of full rebuild (peetzweg#29) Per peetzweg#29 fix-plan point 1: a dead SCStream does not mean the virtual display is gone. If our own display still exists, re-attach the capture to it rather than destroy+create — the full rebuild is what killed the neighbor's stream and ping-ponged the infinite rotation rebuild loop with N>=2 devices. - scheduleCaptureRecovery: if virtualDisplay still present, re-attach capture only (findSCDisplay + startCapture at pixel res), fallback to full rebuild on failure - capture at points*2 @2x (matches setupExtend), not SCDisplay.width (logical) - peetzweg#9's missingTicks debounce already covers peetzweg#29 point 2 (enforcement recovery) - point 3 (serialize rebuilds across sessions) left as follow-up: needs 2-device repro Visual/loop verification needs 2 devices (iPhone+iPad) — untested on single device.
kdbhalala
force-pushed
the
feat/mac-29-capture-reattach
branch
from
July 16, 2026 08:10
0a46602 to
d4dba08
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(mac): re-attach capture on stream death instead of full display rebuild (#29)
Addresses issue #29 (rotation infinite rebuild loop) — fix-plan point 1.
Root cause
scheduleCaptureRecoveryresponded to a deadSCStreamwith a fulldisplay destroy+create (
reconfigure). With ≥2 devices that rebuild killsthe neighbor's stream (OS side effect), whose recovery rebuilds its
display, killing the first — an endless ~3s ping-pong. Observed live
2026-06-11 (iPhone USB + iPad USB).
Fix
A dead stream does NOT mean the display is gone. If our own virtual display
still exists, re-attach the capture to it (no destroy/create) — this alone
breaks the loop. Full
reconfigureis now only the fallback when the displayis genuinely gone (e.g. display sleep tore it down).
scheduleCaptureRecovery: checkCGDisplayBounds(vd.displayID); if live,findSCDisplay+startCaptureat pixel res (points*2 @2x, matchingsetupExtend); on failure fall back to full rebuild.missingTicksdebounce already implements Multi-device: rotation triggers infinite cross-session rebuild loop (capture recovery rebuilds the display) #29 point 2 (enforcementrecovery no longer amplifies the loop).
Not in this PR (follow-ups)
a 2-device repro to validate; left separate to keep this PR minimal.
Verification
runnable on a single device. Manual: 2 connected, rotate one then the other
within ~10s, watch
/tmp/opensidecar-mac.logfor alternatingreconfiguring/-3815/capture died(should be absent after fix).References #29, #9, #26.