mac-avcapture: Catch NSException from startRunning#13426
Conversation
-[AVCaptureSession startRunning] can throw an NSException after a camera hot-plug. The call in startCaptureSession runs on the session queue with no @try/@catch, so the exception escapes the dispatch block and OBS aborts via _objc_terminate. Reproduces frequently on macOS 26.4.1 / OBS 32.1.2 by powering on a switched USB hub hosting a capture device while OBS is running. Wrap startRunning and stopRunning in @try/@catch and log instead. AVFoundation re-fires deviceConnected: as the device settles, so the source recovers on its own.
|
Closing in favour of a corrected fix. The right change is to balance the unbalanced |
|
Please do not submit a new fix until it has been built and tested, and even then only if all lines have been human-written. |
|
Apologies. I created a draft ( #13427 ) with the same approach but will simply close it and give up if the artifact doesn't fix the problem while testing. The build and dependency friction of OBS is too high for just a oneoff bugfix, that's why I was just piggybacking on CI for building. |
|
This is a wildly inappropriate use of our repository, creating noise and putting burden on us as maintainers. If you are not willing to do the bare minimum of building and testing the changes you are proposing, then don't submit them. You have now created an issue in violation of our AI policy, submitted a PR based on the false assumptions of the AI slop which wasn't tested, and you were directly requested not to submit a new change until it was tested yet did so anyway. I recommend taking the time to review our contribution guidelines before making any additional submissions to our repository. |
|
Apologies for the noise. You're right that I shouldn't have opened the new PR before testing. Just for the record, since the technical substance wasn't discussed: I pulled #13427 's macOS arm64 CI artifact and the hot-plug crash no longer reproduces with the change applied. Leaving it at that. |
Description
Wrap
-[AVCaptureSession startRunning]andstopRunningin@try/@catch. The unhandled NSException currently aborts OBS.Motivation and Context
Reproduces frequently on macOS 26.4.1 / OBS 32.1.2 when a camera on a switched USB hub hot-plugs while OBS is running. Crash trace ends in
startRunning->objc_exception_throw->abort. With the guard in place the source error-logs and recovers on the nextdeviceConnected:notification.This behaviour is documented in Apple's AVFoundation SDK header (
AVCaptureSession.h, discussion onbeginConfiguration/commitConfiguration):Log: https://obsproject.com/logs/8S3wBZPQ2vtcOcmB
Crash: https://obsproject.com/logs/crashes/R51BD5uJRNxyCSqe
How Has This Been Tested?
Not built locally yet. Will test against the CI artifact before requesting merge.
Types of changes
Checklist