From f6b875c8a7427c6e77dc3a4bc34e64429f425035 Mon Sep 17 00:00:00 2001 From: Andrey Efremov Date: Tue, 17 Dec 2019 23:36:27 +0300 Subject: [PATCH] Fixed crash on iOS13, methods beginGeneratingDeviceOrientationNotifications and endGeneratingDeviceOrientationNotifications. 1. On iOS13 the implementation of methods begin- and endGeneratingDeviceOrientationNotifications changed and now are looks like "not threadsafe" (in specific sence) - they should be called only on the main thread. This fact is not documented. And may be a mistake. 2. By the Apple official documentation methods begin- and endGeneratingDeviceOrientationNotifications should be balanced. (Each begin- method should be balanced with end- method.) By the reason two above facts they consequences merged and produced the "floating" NSInternalInconsistencyException crash. Bug: webrtc:11216 Change-Id: Ibedd5bba7476cc687de3b9b04be49e3cceac1d27 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/162205 Reviewed-by: Anders Carlsson Commit-Queue: Anders Carlsson Cr-Commit-Position: refs/heads/master@{#30121} --- AUTHORS | 1 + .../components/capturer/RTCCameraVideoCapturer.m | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 5f8113f5a4..8b63772068 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,6 +6,7 @@ Akshay Shah Alexander Brauckmann Alexandre Gouaillard Andrew MacDonald +Andrey Efremov Anil Kumar Ben Strong Bob Withers diff --git a/sdk/objc/components/capturer/RTCCameraVideoCapturer.m b/sdk/objc/components/capturer/RTCCameraVideoCapturer.m index 744edf6ae5..f83c03e4c0 100644 --- a/sdk/objc/components/capturer/RTCCameraVideoCapturer.m +++ b/sdk/objc/components/capturer/RTCCameraVideoCapturer.m @@ -41,6 +41,7 @@ const int64_t kNanosecondsPerSecond = 1000000000; RTCVideoRotation _rotation; #if TARGET_OS_IPHONE UIDeviceOrientation _orientation; + BOOL _generatingOrientationNotifications; #endif } @@ -158,7 +159,12 @@ const int64_t kNanosecondsPerSecond = 1000000000; RTCLogInfo("startCaptureWithDevice %@ @ %ld fps", format, (long)fps); #if TARGET_OS_IPHONE - [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; + dispatch_async(dispatch_get_main_queue(), ^{ + if (!self->_generatingOrientationNotifications) { + [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; + self->_generatingOrientationNotifications = YES; + } + }); #endif self.currentDevice = device; @@ -200,7 +206,12 @@ const int64_t kNanosecondsPerSecond = 1000000000; [self.captureSession stopRunning]; #if TARGET_OS_IPHONE - [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; + dispatch_async(dispatch_get_main_queue(), ^{ + if (self->_generatingOrientationNotifications) { + [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; + self->_generatingOrientationNotifications = NO; + } + }); #endif self.isRunning = NO; if (completionHandler) {