Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS 14.0.1 crashes with bundled WebRTC.framework when calling (begin|end)GeneratingDeviceOrientationNotifications M69 and M75 but not M84 #578

Closed
1 task
pasmat opened this issue Oct 5, 2020 · 13 comments · Fixed by #585
Assignees
Labels
Milestone

Comments

@pasmat
Copy link

pasmat commented Oct 5, 2020

Please read first!

Please use Public Google Group (mailing list) for general technical discussions and questions.

  • [*] I have used Google with the error message or bug in association with the library and Cordova words to make sure the issue I'm reporting is only related to iOSRTC.
  • I have provided steps to reproduce (e.g. sample code or updated extra/renderer-and-libwebrtc-tests.js file).
  • [*] I have provided third party library name and version, ios, Xcode and plugin version and adapter.js version if used.

Note: If the checkboxes above are not checked (which you do after the issue is posted), the issue will be closed, removing this checkbox will result in automatic closed issue.

Versions affected

  • Cordova version 10.0.0:
  • Cordova iOS version 6.1.1:
  • Plugin version master branch:
  • iOS version 14.0.1:
  • Xcode version 12.0.1:
  • WebRTC-adapter version 7.4.0:
  • WebRTC Framework version M69:

Description

The bundled WebRTC Framework causes crash, due to RTCCameraVideoCapturer.startCapture calling UIDevices beginGeneratingDeviceOrientationNotifications on non main thread

I used the linked guide to build WebRTC framework and modified RTCCameraVideoCapturer.m so that instead of calling the beginGeneratingDeviceOrientationNotifications and endGeneratingDeviceOrientationNotifications via RTCDispatchers RTCDispatcherTypeCaptureSession, I call them on RTCDispatcherTypeMain, and it works as expected.

I can't find any documentation regarding the changes to this functions behavior on iOS 14, but this works as expected on my iPad running iOS 13, and used to work on my iPhone running iOS 14.

Steps to reproduce

Run anything on iOS 14.0.1 that accesses the camera using cordova-plugin-iosrtc

Expected results

No crash

Actual results

Crash
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'threading violation: expected the main thread'

@hthetiot hthetiot added the bug label Oct 6, 2020
@hthetiot hthetiot self-assigned this Oct 6, 2020
@hthetiot hthetiot added this to the 6.0.14 milestone Oct 6, 2020
@hthetiot
Copy link
Contributor

hthetiot commented Oct 7, 2020

hello @pasmat you modifed RTCCameraVideoCapturer.m in your WebRTC build ?
can you provide a diff.

@hthetiot
Copy link
Contributor

hthetiot commented Oct 7, 2020

@agelito
Copy link

agelito commented Oct 8, 2020

Hello @hthetiot I've tried M84 #545 and it doesn't crash on iOS 14.0.1 iPad Air 2.

@pasmat
Copy link
Author

pasmat commented Oct 11, 2020

diff webrtc-M69/sdk/objc/Framework/Classes/PeerConnection/RTCCameraVideoCapturer.m webrtc-M69\ 2/sdk/objc/Framework/Classes/PeerConnection/RTCCameraVideoCapturer.m

156,158d155
<   [RTCDispatcher
<       dispatchAsyncOnType:RTCDispatcherTypeMain
<                     block:^{
160d156
<                     }];
201,203d196
<   [RTCDispatcher
<       dispatchAsyncOnType:RTCDispatcherTypeMain
<                     block:^{
205d197
<                     }];

Here's the diff for M69 WebRTC that fixes it for 14.0.1.

If this is fixed on M84 as suggested by @agelito - that's must be the better fix, if it has no other compatibility issues.

Thanks.

@hthetiot
Copy link
Contributor

hthetiot commented Oct 16, 2020

First, it does not crash for me at all on iOS 14.0.1 so fare on iPad Pro and iPhone 6 and 11 on 14.0.1.
Second, thank you @pasmat for the diff, i did edit your comment to make the diff more readable, but its not clear for me, did you simply remove the RTCDispatcher to use main thread ?

@hthetiot hthetiot modified the milestones: 6.0.14, 6.0.x Oct 16, 2020
@hthetiot hthetiot added libwebrtc webrtc-api webrtc-api related labels Oct 16, 2020
@hthetiot
Copy link
Contributor

hthetiot commented Oct 16, 2020

I have provided steps to reproduce (e.g. sample code or updated extra/renderer-and-libwebrtc-tests.js file).

Can you provide a modified extra/renderer-and-libwebrtc-tests.js file to reproduce ? you did not exactly provided it.

Notice I cannot reproduce this issue, can you also try cordova 9 for me.

@hthetiot hthetiot modified the milestones: 6.0.x, 6.0.15 Oct 16, 2020
@hthetiot hthetiot changed the title iOS 14.0.1 crashes with bundled WebRTC.framework iOS 14.0.1 crashes with bundled WebRTC.framework M69 and M75 but not M84 Oct 16, 2020
@hthetiot
Copy link
Contributor

Here is minor update on BuildWebRTCLib to support Xcode 12:

@pasmat did you have warning that where treated as errors, if not, what version of Xcode are you using?

@hthetiot
Copy link
Contributor

Updated difff from @pasmat
diff --git i/sdk/objc/Framework/Classes/PeerConnection/RTCCameraVideoCapturer.m w/sdk/objc/Framework/Classes/PeerConnection/RTCCameraVideoCapturer.m

index 8f93937c75..e21cc76280 100644
--- i/sdk/objc/Framework/Classes/PeerConnection/RTCCameraVideoCapturer.m
+++ w/sdk/objc/Framework/Classes/PeerConnection/RTCCameraVideoCapturer.m
@@ -148,7 +148,7 @@ const int64_t kNanosecondsPerSecond = 1000000000;
              completionHandler:(nullable void (^)(NSError *))completionHandler {
   _willBeRunning = YES;
   [RTCDispatcher
-      dispatchAsyncOnType:RTCDispatcherTypeCaptureSession
+      dispatchAsyncOnType:RTCDispatcherTypeMain
                     block:^{
                       RTCLogInfo("startCaptureWithDevice %@ @ %ld fps", format, (long)fps);

@@ -184,7 +184,7 @@ const int64_t kNanosecondsPerSecond = 1000000000;
 - (void)stopCaptureWithCompletionHandler:(nullable void (^)(void))completionHandler {
   _willBeRunning = NO;
   [RTCDispatcher
-      dispatchAsyncOnType:RTCDispatcherTypeCaptureSession
+      dispatchAsyncOnType:RTCDispatcherTypeMain
                     block:^{
                       RTCLogInfo("Stop");
                       _currentDevice = nil;

testing fix now.

@hthetiot hthetiot changed the title iOS 14.0.1 crashes with bundled WebRTC.framework M69 and M75 but not M84 iOS 14.0.1 crashes with bundled WebRTC.framework when calling (begin|end)GeneratingDeviceOrientationNotifications M69 and M75 but not M84 Oct 17, 2020
@hthetiot hthetiot modified the milestones: 6.0.15, 6.0.14 Oct 17, 2020
@hthetiot
Copy link
Contributor

hthetiot commented Oct 17, 2020

@pasmat can you test the PR there #585 (see instructions).
I confirmed the fix, but something odd is that existing application i have are working fine without this fix, only iosrtc-sample seem to be able to reproduce.

@hthetiot
Copy link
Contributor

I'm closing for now, please comment if fix not working but it does for me.

@Sukumaran001

This comment was marked as abuse.

@Sukumaran001

This comment was marked as off-topic.

@hthetiot

This comment was marked as off-topic.

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