Search code examples
swiftwebrtcappdelegatejanusrtcpeerconnection

Webrtc Swift - Thread 1: EXC_BAD_ACCESS (code=1, address=0xd000000000000040)


I am using Janus videoroom with Webrtc. Everything working fine. But when i go for ending call. And dismiss the current view controller - App Crashed.

I am unable to get the point of crashing so i can resolve.

the current view disappeared fine also. Logs shows this:

callDropButton Clicked
Videoroom viewDidDisappear
Videoroom screen dismissed completely

I am getting the crash at this 1st line of Appdelegate:

class AppDelegate: UIResponder, UIApplicationDelegate {

I am also attaching backtrace logs for more info. But this is not making any sence to me:

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xd000000000000040)
frame #0: 0x00000001012e0024 WebRTC`___lldb_unnamed_symbol6199$$WebRTC + 120
frame #1: 0x00000001013c70f0 WebRTC`___lldb_unnamed_symbol12553$$WebRTC + 44
frame #2: 0x00000001013c7078 WebRTC`___lldb_unnamed_symbol12551$$WebRTC + 128
frame #3: 0x00000001013c6964 WebRTC`___lldb_unnamed_symbol12523$$WebRTC + 12
frame #4: 0x00000001013c6944 WebRTC`___lldb_unnamed_symbol12521$$WebRTC + 52
frame #5: 0x00000001012e16b0 WebRTC`___lldb_unnamed_symbol6278$$WebRTC + 36
frame #6: 0x00000001a37357cc libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 148
frame #7: 0x00000001a37456b8 libobjc.A.dylib`objc_destructInstance + 68
frame #8: 0x00000001a3745720 libobjc.A.dylib`object_dispose + 16
frame #9: 0x00000001012f343c WebRTC`___lldb_unnamed_symbol6908$$WebRTC + 328
frame #10: 0x000000010050c8b0 Interpret`outlined destroy of RTCVideoTrack? at <compiler-generated>:0
frame #11: 0x00000001005346ec Interpret`@objc ConnectionViewController.__ivar_destroyer(self=0x0000000154016800) at ConnectionViewController.swift:0
frame #12: 0x00000001a37357cc libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 148
frame #13: 0x00000001a37456b8 libobjc.A.dylib`objc_destructInstance + 68
frame #14: 0x00000001a3745720 libobjc.A.dylib`object_dispose + 16
frame #15: 0x00000001d04a5de8 UIKitCore`-[UIResponder dealloc] + 152
frame #16: 0x00000001cfeced0c UIKitCore`-[UIViewController dealloc] + 1748
frame #17: 0x00000001cfe07594 UIKitCore`-[UIPresentationController .cxx_destruct] + 372
frame #18: 0x00000001a37357cc libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 148
frame #19: 0x00000001a37456b8 libobjc.A.dylib`objc_destructInstance + 68
frame #20: 0x00000001a3745720 libobjc.A.dylib`object_dispose + 16
frame #21: 0x00000001cfe030fc UIKitCore`-[UIPresentationController dealloc] + 60
frame #22: 0x00000001cfe08d5c UIKitCore`-[_UIFullscreenPresentationController dealloc] + 60
frame #23: 0x00000001a3ff7a44 libsystem_blocks.dylib`_Block_release + 152
frame #24: 0x00000001cfefbaf8 UIKitCore`-[_UIViewControllerTransitionContext .cxx_destruct] + 116
frame #25: 0x00000001a37357cc libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 148
frame #26: 0x00000001a37456b8 libobjc.A.dylib`objc_destructInstance + 68
frame #27: 0x00000001a3745720 libobjc.A.dylib`object_dispose + 16
frame #28: 0x00000001cfefa3f8 UIKitCore`-[_UIViewControllerTransitionContext dealloc] + 60
frame #29: 0x00000001cfefbbb0 UIKitCore`-[_UIViewControllerOneToOneTransitionContext dealloc] + 84
frame #30: 0x00000001a37357cc libobjc.A.dylib`object_cxxDestructFromClass(objc_object*, objc_class*) + 148
frame #31: 0x00000001a37456b8 libobjc.A.dylib`objc_destructInstance + 68
frame #32: 0x00000001a3745720 libobjc.A.dylib`object_dispose + 16
frame #33: 0x00000001a3ff7a44 libsystem_blocks.dylib`_Block_release + 152
frame #34: 0x00000001a444ca38 CoreFoundation`-[__NSSingleObjectArrayI dealloc] + 44
frame #35: 0x00000001d04870e8 UIKitCore`_runAfterCACommitDeferredBlocks + 356
frame #36: 0x00000001d0475bfc UIKitCore`_cleanUpAfterCAFlushAndRunDeferredBlocks + 352
frame #37: 0x00000001d04a2a6c UIKitCore`_afterCACommitHandler + 116
frame #38: 0x00000001a44ef4fc CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
frame #39: 0x00000001a44ea224 CoreFoundation`__CFRunLoopDoObservers + 412
frame #40: 0x00000001a44ea7a0 CoreFoundation`__CFRunLoopRun + 1228
frame #41: 0x00000001a44e9fb4 CoreFoundation`CFRunLoopRunSpecific + 436
frame #42: 0x00000001a66eb79c GraphicsServices`GSEventRunModal + 104
frame #43: 0x00000001d047bc38 UIKitCore`UIApplicationMain + 212
* frame #44: 0x0000000100522d7c Interpret`main at AppDelegate.swift:13:7
frame #45: 0x00000001a3fad8e0 libdyld.dylib`start + 4

Solution

  • Make sure you have something like this in your deinit ("screen dismissed completely"?):

    rtcAudioSession.remove(self)
    peerConnection.close()
    [localAudioTrack,
     localVideoTrack,
     remoteAudioTrack,
     remoteVideoTrack,
    ].forEach { track in
        track.isEnabled = false
    }
    

    Check on every WebRTC object you've created, if the class have something like close(), isEnabled = false, etc, you should call it in deinit.

    According to your crashlog, the problem is in one of RTCVideoTrack objects. Try commenting out all the code that creates any of the RTCVideoTrack and see if that helps. If it helps, uncomment them out one by one to determine which one is causing the problem.