obs-studio icon indicating copy to clipboard operation
obs-studio copied to clipboard

mac-avcapture: Avoid possible bad access on device connect events

Open jcm93 opened this issue 1 month ago • 0 comments

Description

Adjusts the logic in the callback for new device connections on a mac-avcapture source to avoid reading from the currently-stored AVCaptureDevice handle, because the object corresponding to that instance could be in the process of being deallocated.

Motivation and Context

Sporadic crash reports have been received for several releases now winding up in this callback, on what is apparently a null read of the current device's properties. This occurs specifically when the newly connected device's UUID matches that of the stored device; so presumably this crash occurs with one or more disconnect-reconnect events in quick succession.

Looking at the AVFoundation documentation, it seems like it is a bad assumption that an AVCaptureDevice object will persist for any length of time after the physical device corresponding to it has been disconnected. Thus, our source should not try to read from the device object unless we are confident that the device connection corresponding to that object is alive.

How Has This Been Tested?

Made sure the sources still work on macOS 15.7.1.

Types of changes

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

Checklist:

  • [x] My code has been run through clang-format.
  • [x] I have read the contributing document.
  • [x] My code is not on the master branch.
  • [x] The code has been tested.
  • [x] All commit messages are properly formatted and commits squashed where appropriate.
  • [x] I have included updates to all appropriate documentation.

jcm93 avatar Nov 26 '25 17:11 jcm93