Skip to content

mac-avcapture: Catch NSException from startRunning#13426

Closed
2opremio wants to merge 1 commit into
obsproject:masterfrom
2opremio:mac-avcapture-startrunning-exception
Closed

mac-avcapture: Catch NSException from startRunning#13426
2opremio wants to merge 1 commit into
obsproject:masterfrom
2opremio:mac-avcapture-startrunning-exception

Conversation

@2opremio
Copy link
Copy Markdown

@2opremio 2opremio commented May 11, 2026

Description

Wrap -[AVCaptureSession startRunning] and stopRunning in @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 next deviceConnected: notification.

This behaviour is documented in Apple's AVFoundation SDK header (AVCaptureSession.h, discussion on beginConfiguration / commitConfiguration):

-beginConfiguration / -commitConfiguration are AVCaptureSession's mechanism for batching multiple configuration operations on a running session into atomic updates. [...] If you've called -beginConfiguration, you must call -commitConfiguration before invoking -startRunning or -stopRunning, otherwise an NSGenericException is thrown.

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

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines.
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

-[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.
@2opremio
Copy link
Copy Markdown
Author

Closing in favour of a corrected fix. The right change is to balance the unbalanced beginConfiguration in configureSession (the documented root cause of the NSException), not to wrap startRunning in a catch. New PR incoming.

@2opremio 2opremio closed this May 11, 2026
@Fenrirthviti
Copy link
Copy Markdown
Member

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.

@2opremio
Copy link
Copy Markdown
Author

2opremio commented May 12, 2026

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.

@Fenrirthviti
Copy link
Copy Markdown
Member

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.

@2opremio
Copy link
Copy Markdown
Author

2opremio commented May 12, 2026

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants