mac-avcapture: Lock device outside session config#13427
Closed
2opremio wants to merge 1 commit into
Closed
Conversation
configureSession calls -[AVCaptureSession beginConfiguration] before -[AVCaptureDevice lockForConfiguration:], and returns NO without a matching commitConfiguration when the lock fails. lockForConfiguration can fail transiently during a USB hot-plug while AVFoundation is still settling the newly enumerated device. On the next deviceConnected: notification, switchCaptureDevice and configureSession run more begin/commit pairs, but each begin requires its own commit, so the outermost begin from the previous failed attempt stays uncommitted. When startCaptureSession is finally dispatched, -[AVCaptureSession startRunning] raises NSGenericException per Apple's documented invariant: If you've called -beginConfiguration, you must call -commitConfiguration before invoking -startRunning or -stopRunning, otherwise an NSGenericException is thrown. -- AVFoundation/AVCaptureSession.h Nothing in OBS catches the exception, so OBS aborts via _objc_terminate. Reproduces frequently on macOS 26.4.1 / OBS 32.1.2 with a camera on a switched USB hub powering on while OBS is running. Move lockForConfiguration before beginConfiguration. The lock operates on the AVCaptureDevice, not the session, so it doesn't belong inside the session configuration batch. The early return on lock failure now happens before any begin, keeping begin/commit balanced on every path.
7 tasks
Author
|
For anyone else hitting this crash: the change does seem to fix it (tested with this PR's CI artifact). See #13426 for context on why this was closed. |
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.
Description
Move
lockForConfiguration:out of the session config batch inconfigureSession. The lock isn't a session operation and the old order leaked an unbalancedbeginConfigurationon lock failure, which eventually crashed OBS onstartRunning.Motivation and Context
lockForConfiguration:can fail on a USB hot-plug while the device is still settling. With the lock insidebeginConfiguration/commitConfiguration, the early return on failure left the session mid-config. The nextdeviceConnected:opens more nested begin/commit pairs but the outer one stays uncommitted, thenstartRunningthrows:(
AVCaptureSession.h)OBS doesn't catch it and aborts. Repros frequently on a Mac Studio M1 Ultra (macOS 26.4.1, OBS 32.1.2) with a camera on a switched USB hub.
Log: https://obsproject.com/logs/8S3wBZPQ2vtcOcmB
Crash: https://obsproject.com/logs/crashes/R51BD5uJRNxyCSqe
Supersedes #13426.
How Has This Been Tested?
Building locally. Will update before marking ready for review.
Types of changes
Checklist