@@ -228,33 +228,36 @@ static void av_capture_destroy(void *av_capture)
228228 if (!capture) {
229229 return ;
230230 }
231+ // / It is possible that the source's serial queue is still creating this source, so perform destruction
232+ // / synchronously on that queue to ensure the source is fully initialized before being destroyed.
233+ dispatch_sync (capture.sessionQueue , ^{
234+ OBSAVCaptureInfo *capture_info = capture.captureInfo ;
231235
232- OBSAVCaptureInfo *capture_info = capture.captureInfo ;
233-
234- [capture stopCaptureSession ];
235- [capture.deviceInput.device unlockForConfiguration ];
236+ [capture stopCaptureSession ];
237+ [capture.deviceInput.device unlockForConfiguration ];
236238
237- if (capture_info->isFastPath ) {
238- pthread_mutex_destroy (&capture_info->mutex );
239- }
239+ if (capture_info->isFastPath ) {
240+ pthread_mutex_destroy (&capture_info->mutex );
241+ }
240242
241- if (capture_info->videoFrame ) {
242- bfree (capture_info->videoFrame );
243- capture_info->videoFrame = NULL ;
244- }
243+ if (capture_info->videoFrame ) {
244+ bfree (capture_info->videoFrame );
245+ capture_info->videoFrame = NULL ;
246+ }
245247
246- if (capture_info->audioFrame ) {
247- bfree (capture_info->audioFrame );
248- capture_info->audioFrame = NULL ;
249- }
248+ if (capture_info->audioFrame ) {
249+ bfree (capture_info->audioFrame );
250+ capture_info->audioFrame = NULL ;
251+ }
250252
251- if (capture_info->sampleBufferDescription ) {
252- capture_info->sampleBufferDescription = NULL ;
253- }
253+ if (capture_info->sampleBufferDescription ) {
254+ capture_info->sampleBufferDescription = NULL ;
255+ }
254256
255- bfree (capture_info);
257+ bfree (capture_info);
256258
257- CFBridgingRelease ((__bridge CFTypeRef _Nullable)(capture));
259+ CFBridgingRelease ((__bridge CFTypeRef _Nullable)(capture));
260+ });
258261}
259262
260263#pragma mark - OBS Module API
0 commit comments