How to debug with breakpoint when crash line is the App Delegate? - swift

Ever since upgrading to the latest Xcode, I've experienced random/intermittent crashes on app launch that I can only reproduce by launching the app n times and waiting for it to return. The line that the app crashes on is the top of the App Delegate:
class AppDelegate: UIResponder, UIApplicationDelegate {
I don't know how I'd set a breakpoint here and what I could gather from it. The reported cause of the crash is an NSException error on Thread 1:
[_NSTaggedDate countByEnumeratingWithState:objects:count]: unrecognized selector sent to instance 0x8000000000000000
Backtrace:
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
* frame #0: 0x000000019b7c6d88 libsystem_kernel.dylib`__pthread_kill + 8
frame #1: 0x000000019b6df1e8 libsystem_pthread.dylib`pthread_kill$VARIANT$mp + 136
frame #2: 0x000000019b632934 libsystem_c.dylib`abort + 100
frame #3: 0x000000019b79acc0 libc++abi.dylib`abort_message + 128
frame #4: 0x000000019b78ce10 libc++abi.dylib`demangling_terminate_handler() + 296
frame #5: 0x000000019b6f3e80 libobjc.A.dylib`_objc_terminate() + 124
frame #6: 0x000000019b79a14c libc++abi.dylib`std::__terminate(void (*)()) + 16
frame #7: 0x000000019b79a0e4 libc++abi.dylib`std::terminate() + 44
frame #8: 0x000000019b6f3e04 libobjc.A.dylib`objc_terminate + 12
frame #9: 0x0000000105e2b744 libdispatch.dylib`_dispatch_client_callout + 36
frame #10: 0x0000000105e39710 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 976
frame #11: 0x000000019b94f7fc CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
frame #12: 0x000000019b94a6d0 CoreFoundation`__CFRunLoopRun + 1724
frame #13: 0x000000019b949ce8 CoreFoundation`CFRunLoopRunSpecific + 424
frame #14: 0x00000001a5a9438c GraphicsServices`GSEventRunModal + 160
frame #15: 0x000000019fa78444 UIKitCore`UIApplicationMain + 1932
frame #16: 0x0000000100fc866c FXTracker`main at AppDelegate.swift:8:7
frame #17: 0x000000019b7d18f0 libdyld.dylib`start + 4
In the debug navigator window, it's opened to Thread 1 and there is a drop-down called Original Exception Backtrace which looks like this:
0 _exceptionPreprocess
9 Sequence<>.contains(_:)
10 closure #3 in closure #1 in closure #2 in FXEditorViewController.loadBadges()
19 UIApplicationMain
20 main
21 start
Is it safe to say that the crash is caused by closure #3 in closure #1 in closure #2 in loadBadges()?

In this case you can set exception breakpoints
here
and then here (in Exceptions -> All)

Related

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
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.

How to "Take Priority" of Audio Playback?

I have an audio-playback app that crashes when returning from another audio-playing app when the user attempts to re-start playback. My app works great on it's own and will handle background playback, etc; however when returning from Spotify-like apps it crashes when it starts it's own playback.
I'm guessing there's some sort of "priority" of audio that I should be handling? And taking that priority "back" from whatever audio app previously had it? Just looking for a direction to start looking....thanks!
Backtrace:
thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00000001be4fdec4 libsystem_kernel.dylib__pthread_kill + 8
frame #1: 0x00000001be41d724 libsystem_pthread.dylibpthread_kill$VARIANT$armv81 + 216
frame #2: 0x00000001be36d844 libsystem_c.dylibabort + 100
frame #3: 0x00000001be4c67d4 libc++abi.dylibabort_message + 128
frame #4: 0x00000001be4c69c4 libc++abi.dylibdemangling_terminate_handler() + 296
frame #5: 0x00000001be42e258 libobjc.A.dylib_objc_terminate() + 124
frame #6: 0x00000001be4d3304 libc++abi.dylibstd::__terminate(void (*)()) + 16
frame #7: 0x00000001be4d2ed8 libc++abi.dylib__cxa_rethrow + 144
frame #8: 0x00000001be42e158 libobjc.A.dylibobjc_exception_rethrow + 40
frame #9: 0x00000001be67eb4c CoreFoundationCFRunLoopRunSpecific + 576
frame #10: 0x00000001c861f328 GraphicsServicesGSEventRunModal + 104
frame #11: 0x00000001c278c63c UIKitCoreUIApplicationMain + 1936
frame #12: 0x00000001047c0e78 Sequencer`main at AppDelegate.swift:23:7
frame #13: 0x00000001be508360 libdyld.dylib`start + 4

iphone app with multiple AVAudioPlayer crashes on iOS 6 upon interruption

I have an app that uses multiple AVAudioPlayer objects to play music. On iOS6, this app crashes when it is interrupted by a incoming phone call. The problem does not occur on iOS 4.3, 5.0 or 5.1. When the app crashes, the following stacktrace was seen.
(lldb) thread backtrace
* thread #1: tid = 0x2403, 0x3b905e64 libsystem_c.dylibpthread_mutex_lock + 388, stop reason = instruction step over
frame #0: 0x3b905e64 libsystem_c.dylibpthread_mutex_lock + 388
frame #1: 0x3299bd18 AVFoundationAVAudioPlayerCpp::sessionPropertyListener(unsigned long, unsigned long, void const*) + 124
frame #2: 0x33200b32 AudioToolboxAudioSessionPropertyListeners::CallPropertyListenersImp(unsigned long, unsigned long, void const*) + 170
frame #3: 0x332008cc AudioToolboxAudioSessionPropertyListeners::CallPropertyListeners(unsigned long, unsigned long, void const*) + 244
frame #4: 0x332b4afc AudioToolboxASCallbackReceiver_AudioSessionInterruptionListenerMessage + 184
frame #5: 0x33389dde AudioToolbox_XAudioSessionInterruptionListenerMessage + 70
frame #6: 0x3320058a AudioToolboxmshMIGPerform + 382
frame #7: 0x337a33e6 CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
frame #8: 0x337a338a CoreFoundation__CFRunLoopDoSource1 + 138
frame #9: 0x337a220e CoreFoundation__CFRunLoopRun + 1382
frame #10: 0x3371523c CoreFoundationCFRunLoopRunSpecific + 356
frame #11: 0x337150c8 CoreFoundationCFRunLoopRunInMode + 104
frame #12: 0x372f433a GraphicsServicesGSEventRunModal + 74
frame #13: 0x356312b8 UIKit`UIApplicationMain + 1120
I have added applicationWillResignActive and this does not get called when the crash occurs. I have also added my app delegate as a delegate to the AVAudioPlayer objects and implemented the audioPlayerBeginInterruption method. This method also does not get called when the crash occurs. If I use only 1 or 2 AVAudioPlayer objects, the crash goes away. The crash occurs with 3 more AVAudioPlayer objects, although only 2 of them are playing at a given time and the remaining have been stopped.
Has anyone seen this kind of problem or have any tips?
Thanks.

Calling FBSession.activeSession as instructed to in tutorial, results in NSException

I am trying to enable Facebook login in my iphone app.
I am following the instructions on this page:
https://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/#step4
I have followed the instructions in Step #4 (Logging in to Facebook), but my code crashes when I run it.
This is my method that is causing the crash:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
// We need to properly handle activation of the application with regards to Facebook Login
// (e.g., returning from iOS 6.0 Login Dialog or from fast app switching).
NSLog(#"here 1");
NSLog(#"active session: %#",FBSession.activeSession);
[FBSession.activeSession handleDidBecomeActive];
NSLog(#"here 2");
}
And here is my stack trace at the time of the crash (app name replaced with XXX):
2013-02-11 17:31:17.956 TRIO[9426:907] here 1
* thread #1: tid = 0x2503, 0x324d9960 libobjc.A.dylib`objc_exception_throw, stop reason = breakpoint 1.1
frame #0: 0x324d9960 libobjc.A.dylib`objc_exception_throw
frame #1: 0x3161af98 CoreFoundation`-[NSException raise] + 8
frame #2: 0x0009f7cc XXX`-[FBSession initWithAppID:permissions:defaultAudience:urlSchemeSuffix:tokenCacheStrategy:] + 240 at FBSession.m:236
frame #3: 0x0009f6d6 XXX`-[FBSession initWithAppID:permissions:urlSchemeSuffix:tokenCacheStrategy:] + 46 at FBSession.m:208
frame #4: 0x0009f680 XXX`-[FBSession init] + 32 at FBSession.m:191
frame #5: 0x000a061a XXX`+[FBSession activeSession] + 62 at FBSession.m:568
frame #6: 0x00073c4e XXX`-[AppDelegate applicationDidBecomeActive:] + 66 at AppDelegate.m:118
frame #7: 0x38e3bae2 UIKit`-[UIApplication _stopDeactivatingForReason:] + 342
frame #8: 0x38e219b8 UIKit`-[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 1072
frame #9: 0x38dc9c38 UIKit`-[UIApplication handleEvent:withNewEvent:] + 1004
frame #10: 0x38dc96cc UIKit`-[UIApplication sendEvent:] + 72
frame #11: 0x38dc911a UIKit`_UIApplicationHandleEvent + 6154
frame #12: 0x393605a2 GraphicsServices`_PurpleEventCallback + 590
frame #13: 0x393601d2 GraphicsServices`PurpleEventCallback + 34
frame #14: 0x315f0172 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
frame #15: 0x315f0116 CoreFoundation`__CFRunLoopDoSource1 + 138
frame #16: 0x315eef98 CoreFoundation`__CFRunLoopRun + 1384
frame #17: 0x31561ebc CoreFoundation`CFRunLoopRunSpecific + 356
frame #18: 0x31561d48 CoreFoundation`CFRunLoopRunInMode + 104
frame #19: 0x38e2047c UIKit`-[UIApplication _run] + 668
frame #20: 0x38e1d2f8 UIKit`UIApplicationMain + 1120
frame #21: 0x00073748 XXX`main + 96 at main.m:16
When I run the Facebook sample code, they work fine, and I believe I've added all the required frameworks.
Thanks.
I had the same error as above and it was because I did not add my own FacebookAppID along with the "URL types" key to my project's info.plist

xcode: can't show the exact line of the fault

I am keep seeing such errors but the xcode never shows the line that the error actually happened on, how to set the xcode to show the fault line directly? Till now it just point to the main function.
2012-06-27 21:46:33.513 Chapeng[838:f803] -[SendGiftViewController giftButtonClicked]: unrecognized selector sent to instance 0x6e392a0
The backtrace:
(lldb) bt
* thread #1: tid = 0x1f03, 0x92f359c6 libsystem_kernel.dylib`__pthread_kill + 10, stop reason = signal SIGABRT
frame #0: 0x92f359c6 libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x916e6f78 libsystem_c.dylib`pthread_kill + 106
frame #2: 0x916d7bdd libsystem_c.dylib`abort + 167
frame #3: 0x01e38e78 libc++abi.dylib`_Unwind_DeleteException
frame #4: 0x01e3689e libc++abi.dylib`_ZL17default_terminatev + 34
frame #5: 0x01c94f17 libobjc.A.dylib`_objc_terminate + 94
frame #6: 0x01e368de libc++abi.dylib`_ZL19safe_handler_callerPFvvE + 13
frame #7: 0x01e36946 libc++abi.dylib`std::terminate() + 23
frame #8: 0x01e37b3e libc++abi.dylib`__cxa_rethrow + 83
frame #9: 0x01c94e15 libobjc.A.dylib`objc_exception_rethrow + 47
frame #10: 0x01612de0 CoreFoundation`CFRunLoopRunSpecific + 304
frame #11: 0x01612c9b CoreFoundation`CFRunLoopRunInMode + 123
frame #12: 0x0222b7d8 GraphicsServices`GSEventRunModal + 190
frame #13: 0x0222b88a GraphicsServices`GSEventRun + 103
frame #14: 0x0061b626 UIKit`UIApplicationMain + 1163
frame #15: 0x00001ec2 Chapeng`main + 130 at main.m:16
(lldb)
Add a symbolic breakpoint on objc-exception-throw. A tutorial on this is available here. This should make GDB / LLDB stop execution when an unrecognized selector is sent.
EDIT: after reading your backtrace, it appears you have an invalid IB connection. Check all of your buttons on your view controller, and make sure they are linked to a proper selector.
Press cmd+shift+f and paste giftButtonClicked. It will show the list of string in your project find where you have called this method from any class. This error will raise because giftButtonClicked method was not recognizable at the time of calling