I am experiencing a random crash in the following method:
- (void) addLineToVCard:(NSMutableString **)vCard forKey:(NSString *)key setValue:(NSString *)value
{
[*vCard appendString:[NSString stringWithFormat:#"%#:%#\r\n", key, value]];
}
and I'm calling this as:
NSMutableString* vCard = [NSMutableString string];
[self addLineToVCard:&vCard forKey:#"BEGIN" setValue:#"VCARD"];
[self addLineToVCard:&vCard forKey:#"VERSION" setValue:#"3.0"];
What am I doing wrong ? I could avoid this by passing a reference instead of a pointer object. But I would like to know the reason of crash here.
The crash log:
Crashed: com.apple.main-thread
0 libsystem_kernel.dylib 0x251e6c5c __pthread_kill + 8
1 libsystem_pthread.dylib 0x25290733 pthread_kill + 62
2 libsystem_c.dylib 0x2517b0ad abort + 108
3 libsystem_malloc.dylib 0x252180ad free_list_checksum_botch + 362
4 libsystem_malloc.dylib 0x252181db free_tiny_botch + 66
5 CoreFoundation 0x255332d3 __CFStringChangeSizeMultiple + 1838
6 CoreFoundation 0x2553178b __CFStringCheckAndReplace + 554
7 CoreFoundation 0x25491557 -[__NSCFString appendString:] + 26
8 iPhoneHandheldACT 0x1ae7cf -[ContactDetailViewController addLineToVCard:forKey:setValue:] (ContactDetailViewController.m:3009)
9 iPhoneHandheldACT 0x1ae515 -[ContactDetailViewController assembleVCard:] (ContactDetailViewController.m:2987)
10 iPhoneHandheldACT 0x1adcbd -[ContactDetailViewController shareVCard:] (ContactDetailViewController.m:2927)
11 iPhoneHandheldACT 0x1ad351 __47-[ContactDetailViewController btnSharePressed:]_block_invoke (ContactDetailViewController.m:2813)
12 UIKit 0x29f2cbd9 -[UIAlertController _fireOffActionOnTargetIfValidForAction:] + 68
13 UIKit 0x29f2d283 __85-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:]_block_invoke + 30
14 UIKit 0x29e237e3 -[UIPresentationController transitionDidFinish:] + 1230
15 UIKit 0x29e26a85 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 192
16 UIKit 0x29c04157 -[_UIViewControllerTransitionContext completeTransition:] + 90
17 UIKit 0x29b11ba5 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 540
18 UIKit 0x29b11685 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 204
19 UIKit 0x29b1157f -[UIViewAnimationState animationDidStop:finished:] + 78
20 QuartzCore 0x27b71689 CA::Layer::run_animation_callbacks(void*) + 252
21 libdispatch.dylib 0x250c980f _dispatch_client_callout + 22
22 libdispatch.dylib 0x250d7ba9 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1524
23 CoreFoundation 0x2551db6d __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
24 CoreFoundation 0x2551c067 __CFRunLoopRun + 1574
25 CoreFoundation 0x2546b229 CFRunLoopRunSpecific + 520
26 CoreFoundation 0x2546b015 CFRunLoopRunInMode + 108
27 GraphicsServices 0x26a5bac9 GSEventRunModal + 160
28 UIKit 0x29b3f189 UIApplicationMain + 144
29 iPhoneHandheldACT 0xcbe21 main (main.m:16)
30 libdispatch.dylib 0x25113873 (Missing)
The pointer's pointer is not necessary, just like this:
- (void)addLineToVCard:(NSMutableString *)vCard forKey:(NSString *)key setValue:(NSString *)value
{
[vCard appendFormat:#"%#:%#\r\n", key, value];
}
Then use it:
NSMutableString* vCard = [NSMutableString string];
[self addLineToVCard:vCard forKey:#"BEGIN" setValue:#"VCARD"];
[self addLineToVCard:vCard forKey:#"VERSION" setValue:#"3.0"];
The result:
(lldb) po vCard
BEGIN:VCARD
VERSION:3.0
Related
I am a newbie who is learning OC.
But now when I set an outlet button as a property of my viewcontroller, in order to add an attribute for it, when I write some methods in viewDidLoad, something wrong happened like this:
The only thing I want to do is to set the attributes of the outLetButton.currentTitle
And my code is as follows:
There is nothing wrong with my button.
(void)viewDidLoad {
[super viewDidLoad];
/
NSMutableAttributedString * title = [[NSMutableString alloc] initWithString:self.OutletButton.currentTitle] ;
[title setAttributes:#{NSStrokeWidthAttributeName:#3.0,NSStrokeColorAttributeName:[self.OutletButton tintColor]} range:NSMakeRange(0, [title length])] ;
[self.OutletButton setAttributedTitle:title forState:UIControlStateNormal] ;
}
I used breakout debugging, when I step over [title setAttributes...], it crashed.
First throw call stack
0 CoreFoundation 0x000000010ba0b12b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010b09ff41 objc_exception_throw + 48
2 CoreFoundation 0x000000010ba8c024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010b98df78 forwarding + 1432
4 CoreFoundation 0x000000010b98d958 _CF_forwarding_prep_0 + 120
5 UITextView 0x000000010a791106 -[ViewController viewDidLoad] + 598
6 UIKit 0x000000010c03146c -[UIViewController loadViewIfRequired] + 1235
7 UIKit 0x000000010c0318b9 -[UIViewController view] + 27
8 UIKit 0x000000010befc7cf -[UIWindow addRootViewControllerViewIfPossible] + 122
9 UIKit 0x000000010befced7 -[UIWindow _setHidden:forced:] + 294
10 UIKit 0x000000010bf0fe54 -[UIWindow makeKeyAndVisible] + 42
11 UIKit 0x000000010be828b8 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4737
12 UIKit 0x000000010be87aeb -[UIApplication _runWithMainScene:transitionContext:completion:] + 1720
13 UIKit 0x000000010c2516f8 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 924
14 UIKit 0x000000010c6274c8 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
15 UIKit 0x000000010c2512f1 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 249
16 UIKit 0x000000010c251b6b -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 696
17 UIKit 0x000000010cbcfa69 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 262
18 UIKit 0x000000010cbcf922 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 444
19 UIKit 0x000000010c8ac9c8 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 221
20 UIKit 0x000000010caabb06 _performActionsWithDelayForTransitionContext + 100
21 UIKit 0x000000010c8ac88b -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 231
22 UIKit 0x000000010c626b25 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
23 UIKit 0x000000010be8636a -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523
24 UIKit 0x000000010c461605 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 369
25 FrontBoardServices 0x0000000110158cc0 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338
26 FrontBoardServices 0x00000001101617b5 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 235
27 libdispatch.dylib 0x000000010f3b733d _dispatch_client_callout + 8
28 libdispatch.dylib 0x000000010f3bc9f3 _dispatch_block_invoke_direct + 592
29 FrontBoardServices 0x000000011018d498 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
30 FrontBoardServices 0x000000011018d14e -[FBSSerialQueue _performNext] + 464
31 FrontBoardServices 0x000000011018d6bd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
32 CoreFoundation 0x000000010b9ae101 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
33 CoreFoundation 0x000000010ba4df71 __CFRunLoopDoSource0 + 81
34 CoreFoundation 0x000000010b992a19 __CFRunLoopDoSources0 + 185
35 CoreFoundation 0x000000010b991fff __CFRunLoopRun + 1279
36 CoreFoundation 0x000000010b991889 CFRunLoopRunSpecific + 409
37 GraphicsServices 0x0000000110a219c6 GSEventRunModal + 62
38 UIKit 0x000000010be895d6 UIApplicationMain + 159
39 UITextView 0x000000010a7914df main + 111
40 libdyld.dylib 0x000000010f433d81 start + 1
41 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The issue is because you are initialising NSMutableAttributedString with NSMutableString & then changes its attribute..
The code lets you initialise the variable But NSMutableString doesn't allow you to add attributes so it crashes..
The code should be like this.. (change allocation class to NSMutableAttributedString)
NSMutableAttributedString * title = [[NSMutableAttributedString alloc] initWithString:self.OutletButton.currentTitle] ;
[title setAttributes:#{NSStrokeWidthAttributeName:#3.0,NSStrokeColorAttributeName:[self.OutletButton tintColor]} range:NSMakeRange(0, [title length])] ;
[self.OutletButton setAttributedTitle:title forState:UIControlStateNormal] ;
Thanks.
Crashlytics reported the following error:
Fatal Exception: NSInvalidArgumentException - [_ UIFieldEditorLayoutManager addTextContainer:] unrecognized selector sent to the instance
...
My question is: How can I control this Exception?
Greetings.
Code:
-(void) method{
NSError *authError = nil;
LAContext *laCtx = [[LAContext alloc] init];
if ([laCtx canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
...
}
} else {
[txtField becomeFirstResponder];
self.navigationItem.hidesBackButton = NO;
}
}
The report shows the crash in the line: self.navigationItem.hidesBackButton = NO;. But I think it has to do with the text field (due to the error message).
The crash report indicates:
0 iosApp 0x4e8221 CLSProcessRecordAllThreads + 4362785
1 iosApp 0x4e8221 CLSProcessRecordAllThreads + 4362785
2 iosApp 0x4e8119 CLSProcessRecordAllThreads + 4362521
3 iosApp 0x4dc05f CLSHandler + 4313183
4 iosApp 0x4e6b0b __CLSExceptionRecord_block_invoke + 4356875
5 libdispatch.dylib 0x23739b47 _dispatch_client_callout + 22
6 libdispatch.dylib 0x23745355 _dispatch_barrier_sync_f_invoke + 56
7 iosApp 0x4e650d CLSExceptionRecord + 4355341
8 iosApp 0x4e6335 CLSExceptionRecordNSException + 4354869
9 iosApp 0x4e5e4b CLSTerminateHandler() + 4353611
10 libc++abi.dylib 0x23358e17 std::__terminate(void (*)()) + 78
11 libc++abi.dylib 0x233585f5 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*) + 110
12 libobjc.A.dylib 0x23366eeb objc_exception_throw + 250
13 CoreFoundation 0x23bc5925 __methodDescriptionForSelector + 186
14 CoreFoundation 0x23bc3559 __forwarding __ + 700
15 CoreFoundation 0x23af3c08 _CF_forwarding_prep_0 + 24
16 UIKit 0x27e0bc59 -[UIFieldEditor initWithFrame:] + 584
17 UIKit 0x27d1c44d +[UIFieldEditor sharedFieldEditor] + 88
18 UIKit 0x27e0b7d5 -[UITextField _becomeFirstResponder] + 184
19 UIKit 0x27d8374d -[UIResponder becomeFirstResponder] + 396
20 UIKit 0x27d83b29 -[UIView(Hierarchy) becomeFirstResponder] + 132
21 UIKit 0x27e0a39d -[UITextField becomeFirstResponder] + 48
22 iosApp 0x22a5bd -[MyViewController methodCrashed] (MyViewController.m:175)
23 iosApp 0x229fdf __45-[MyViewController methodLCS]_block_invoke (MyViewController.m:91)
24 Framework1 0x167a3c9 -[MyViewControllerLCS requestAuthorizationWithHandler:] (MyViewControllerLCS.m:48)
25 iosApp 0x229eb5 -[MyViewController methodLCS] (MyViewController.m:106)
26 iosApp 0x229e25 -[MyViewController viewDidAppear:] (MyViewController.m:73)
27 UIKit 0x27d152af -[UIViewController _setViewAppearState:isAnimating:] + 670
28 UIKit 0x27d15837 -[UIViewController _endAppearanceTransition:] + 258
29 UIKit 0x27dd0fdb -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 986
30 UIKit 0x27eab2d7 __49-[UINavigationController _startCustomTransition:]_block_invoke + 210
31 UIKit 0x27e2909f -[_UIViewControllerTransitionContext completeTransition:] + 90
32 UIKit 0x27f8ddfb __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke95 + 682
33 UIKit 0x27d37b25 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 540
34 UIKit 0x27d37605 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 204
35 UIKit 0x27d374ff -[UIViewAnimationState animationDidStop:finished:] + 78
36 QuartzCore 0x25dfea21 CA::Layer::run_animation_callbacks(void*) + 252
37 libdispatch.dylib 0x23739b47 _dispatch_client_callout + 22
38 libdispatch.dylib 0x23747ee1 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1524
39 CoreFoundation 0x23b833fd _CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE_ + 8
40 CoreFoundation 0x23b818f7 __CFRunLoopRun + 1574
41 CoreFoundation 0x23ad4bf9 CFRunLoopRunSpecific + 520
42 CoreFoundation 0x23ad49e5 CFRunLoopRunInMode + 108
43 GraphicsServices 0x24d20ac9 GSEventRunModal + 160
44 UIKit 0x27d64ba1 UIApplicationMain + 144
45 iosApp 0x342779 main (main.m:14)
46 libdispatch.dylib 0x23783873 (Missing)
Usually app works great, but i received issue in Crashlytics. It's happen 1-2 times in week. For 2k-3k users. App work on iOS 7 and later.
Report: Fatal Exception: NSInvalidArgumentException
-[UIPasteboard setString:]: Argument is not an object of type NSString [(null)]
Here stack of thread where app crashed:
Thread : Crashed: com.apple.main-thread
0 libsystem_kernel.dylib 0x38fae1f0 __pthread_kill + 8
1 libsystem_pthread.dylib 0x390167b7 pthread_kill + 58
2 libsystem_c.dylib 0x38f5eff9 abort + 76
3 libc++abi.dylib 0x383ad98f abort_message + 74
4 libc++abi.dylib 0x383c66e7 default_terminate_handler() + 254
5 libobjc.A.dylib 0x389f9f7d _objc_terminate() + 192
6 APPNAME 0x001f1495 CPPExceptionTerminate() (KSCrashSentry_CPPException.mm:193)
7 libc++abi.dylib 0x383c41b3 std::__terminate(void (*)()) + 78
8 libc++abi.dylib 0x383c3a09 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)
9 libobjc.A.dylib 0x389f9dbb objc_exception_throw + 250
10 CoreFoundation 0x2e25ee0d -[NSException initWithCoder:]
11 UIKit 0x30e3e0eb -[UIPasteboard(UIPasteboardDataExtensions) setString:] + 154
12 APPNAME 0x0011cfaf __33-[WebViewController moreActions:]_block_invoke_2 (WebViewController.m:424)
13 UIKit 0x30c74ceb __56-[UIActivityViewController _cleanupActivityWithSuccess:]_block_invoke + 54
14 UIKit 0x30ba87c9 -[UIWindowController transitionViewDidComplete:fromView:toView:removeFromView:] + 1880
15 UIKit 0x30ba7f9f __101-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:]_block_invoke293 + 170
16 UIKit 0x30ba7ecb -[_UIViewControllerTransitionContext completeTransition:] + 74
17 UIKit 0x30ba7db1 -[UITransitionView notifyDidCompleteTransition:] + 288
18 UIKit 0x30ba78c1 -[UITransitionView _didCompleteTransition:] + 944
19 UIKit 0x30ac83b7 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 178
20 UIKit 0x30ac82cf -[UIViewAnimationState animationDidStop:finished:] + 66
21 QuartzCore 0x30712e0b CA::Layer::run_animation_callbacks(void*) + 234
22 libdispatch.dylib 0x38ee2d3f _dispatch_client_callout + 22
23 libdispatch.dylib 0x38ee56c3 _dispatch_main_queue_callback_4CF + 278
24 CoreFoundation 0x2e229641 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
25 CoreFoundation 0x2e227f0d __CFRunLoopRun + 1308
26 CoreFoundation 0x2e192729 CFRunLoopRunSpecific + 524
27 CoreFoundation 0x2e19250b CFRunLoopRunInMode + 106
28 GraphicsServices 0x331016d3 GSEventRunModal + 138
29 UIKit 0x30af3871 UIApplicationMain + 1136
30 APPNAME 0x000b9287 main (main.m:16)
App crahed in WebViewController in function moreActions.
12 APPNAME 0x0011cfaf __33-[WebViewController moreActions:]_block_invoke_2 (WebViewController.m:424)
This Function show UIActivityViewController and one of custom action - copy link to web page.
__weak WebViewController *weakSelf = self;
[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
WebViewController *strongSelf = weakSelf;
if ([activityType isEqualToString:#"VK"]) {
// actions
} else if ([activityType isEqualToString:#"copyLink"]) {
// HERE UIPasteboard!
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:[strongSelf.startUrl absoluteString]];
}
}];
Make sure that [strongSelf.startUrl absoluteString] does not returns nil just before setting it to pasteboard string. I'm pretty sure that your startUrl apparently becomes nil.
Crashlytics reported a crash in my app, and I have no idea of what is happening.
Here is the stacktrace:
Thread : Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x30080e83 __exceptionPreprocess + 130
1 libobjc.A.dylib 0x3a3dd6c7 objc_exception_throw + 38
2 CoreData 0x2fdcf941 -[NSSQLiteStatement cachedSQLiteStatement]
3 CoreData 0x2fdcf18d -[NSSQLiteConnection prepareSQLStatement:] + 52
4 CoreData 0x2fde8edf -[NSSQLChannel selectRowsWithCachedStatement:] + 58
5 CoreData 0x2fea8e1f newFetchedRowsForFetchPlan_MT + 910
6 CoreData 0x2fde8949 -[NSSQLCore fetchRowForObjectID:] + 1180
7 CoreData 0x2fde8311 -[NSSQLCore newValuesForObjectWithID:withContext:error:] + 256
8 CoreData 0x2fde762b _PFFaultHandlerLookupRow + 398
9 CoreData 0x2fde7193 _PF_FulfillDeferredFault + 218
10 CoreData 0x2fdf6449 _PF_ManagedObject_WillChangeValueForKeyIndex + 68
11 CoreData 0x2fdf636b _sharedIMPL_setvfk_core + 110
12 CoreData 0x2fe1995d _PF_Handler_Public_SetProperty + 92
13 CoreData 0x2fe1e2a9 -[NSManagedObject setValue:forKey:] + 124
14 Application 0x0004dc45 -[DateFormatter storeValue:error:] (DateFormatter.m:65)
15 Application 0x0004ee17 -[Formatter storeValue:inObject:] (Formatter.m:176)
16 Application 0x0002b5c5 -[NSManagedObject(App) setValuesForKeysWithReceivedDictionary:] (NSManagedObject+App.m:320)
17 Application 0x0002b8f3 -[NSManagedObject(App) setValuesForKeysWithReceivedDictionary:] (NSManagedObject+App.m:377)
18 Application 0x0006352d -[ODataGetOperation processResult:] (ODataGetOperation.m:220)
19 Application 0x0004420b -[ODataOperation connectionDidFinishLoading:] (ODataOperation.m:741)
20 Foundation 0x309bb47f __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 54
21 Foundation 0x309bb3c1 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 204
22 Foundation 0x309bb2dd -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 60
23 CFNetwork 0x2fceaf8f ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 74
24 CFNetwork 0x2fce9b8f ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 54
25 CFNetwork 0x2fd1b337 ___ZNK17CoreSchedulingSet13_performAsyncEPKcU13block_pointerFvvE_block_invoke + 18
26 CoreFoundation 0x2ffb3ea1 CFArrayApplyFunction + 36
27 CFNetwork 0x2fc81e05 RunloopBlockContext::perform() + 164
28 CFNetwork 0x2fc81cd5 MultiplexerSource::perform() + 220
29 CFNetwork 0x2fc81b65 MultiplexerSource::_perform(void*) + 48
30 CoreFoundation 0x3004bf1f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
31 CoreFoundation 0x3004b3e7 __CFRunLoopDoSources0 + 206
32 CoreFoundation 0x30049bd7 __CFRunLoopRun + 630
33 CoreFoundation 0x2ffb4471 CFRunLoopRunSpecific + 524
34 CoreFoundation 0x2ffb4253 CFRunLoopRunInMode + 106
35 Foundation 0x309a2697 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 254
36 Application 0x00043b4b -[ODataOperation send] (ODataOperation.m:548)
37 Application 0x0004277f -[ODataOperation operationWillStartPreparingData] (ODataOperation.m:131)
38 Foundation 0x30a5396d __NSOQSchedule_f + 60
39 libdispatch.dylib 0x3a8c64b7 _dispatch_async_redirect_invoke + 110
40 libdispatch.dylib 0x3a8c77d9 _dispatch_root_queue_drain + 224
41 libdispatch.dylib 0x3a8c79c5 _dispatch_worker_thread2 + 56
42 libsystem_pthread.dylib 0x3a9f1dff _pthread_wqthread + 298
43 libsystem_pthread.dylib 0x3a9f1cc4 start_wqthread + 8
And there is the last method that calls setValue:forKey: in an NSManagedObject subclass
- (BOOL)storeValue:(void *)theValue error:(NSError **)theError
{
NSString * value = (__bridge NSString *)theValue;
NSString * errorMessage = nil;
if (![value length] && !isOptional)
errorMessage = [NSString stringWithFormat: NSLocalizedString(#"Value cannot be nil or empty (Date) for field %#", #""), varName];
else
{
NSDate * date = nil;
if ([value length])
{
date = [NSDate dateWithISO8601: value];
if (!date)
errorMessage = [NSString stringWithFormat: NSLocalizedString(#"Invalid date %# for field %#", #""), theValue, varName];
}
if (IvarAddress)
*((__strong NSDate **) IvarAddress) = date;
else
[currentObject setValue: date forKey: varName];
}
if (errorMessage)
{
if (theError)
*theError = [NSError errorWithDomain: AppDomain code: NSFormattingError userInfo: #{ NSLocalizedDescriptionKey: errorMessage }];
#ifdef DEBUG
NSLog(#"Formatter error: %#", errorMessage);
#endif
return NO;
}
return YES;
}
I am completely open to any suggestion :)
Update : The key exists, and the value being set is an NSDate so it's an attribute of the NSManagedObject, not a relationship.
Update 2 :
I also have another crash with that method (stack trace is not exactly the same) :
Thread : Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x30080e83 __exceptionPreprocess + 130
1 libobjc.A.dylib 0x3a3dd6c7 objc_exception_throw + 38
2 CoreData 0x2fddfacb -[NSSQLCore _obtainOpenChannel] + 234
3 CoreData 0x2fea8ded newFetchedRowsForFetchPlan_MT + 860
4 CoreData 0x2fde8949 -[NSSQLCore fetchRowForObjectID:] + 1180
5 CoreData 0x2fde8311 -[NSSQLCore newValuesForObjectWithID:withContext:error:] + 256
6 CoreData 0x2fde762b _PFFaultHandlerLookupRow + 398
7 CoreData 0x2fde7193 _PF_FulfillDeferredFault + 218
8 CoreData 0x2fdf6449 _PF_ManagedObject_WillChangeValueForKeyIndex + 68
9 CoreData 0x2fdf636b _sharedIMPL_setvfk_core + 110
10 CoreData 0x2fe1995d _PF_Handler_Public_SetProperty + 92
11 CoreData 0x2fe1e2a9 -[NSManagedObject setValue:forKey:] + 124
12 Application 0x000fcc45 -[DateFormatter storeValue:error:] (DateFormatter.m:65)
13 Application 0x000fde17 -[Formatter storeValue:inObject:] (Formatter.m:176)
14 Application 0x000da5c5 -[NSManagedObject(App) setValuesForKeysWithReceivedDictionary:] (NSManagedObject+.m:320)
15 Application 0x000da8f3 -[NSManagedObject(App) setValuesForKeysWithReceivedDictionary:] (NSManagedObject+.m:377)
16 Application 0x0011252d -[ODataGetOperation processResult:] (ODataGetOperation.m:220)
17 Application 0x000f320b -[ODataOperation connectionDidFinishLoading:] (ODataOperation.m:741)
18 Foundation 0x309bb47f __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 54
19 Foundation 0x309bb3c1 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 204
20 Foundation 0x309bb2dd -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 60
The exception message also is different :
_obtainOpenChannel -- NSSQLCore 0x15ef3780: no database channel is available
But I think they are two related issues.
So I finally found the reasons which were all related to multithreading/concurrency issues. Basically updating the same objects on two threads at the same time..
The recently added core data debug flags (-com.apple.CoreData.ConcurrencyDebug 1) were used to figure out what was happening.
My app was recently rejected for a crash when loading a tableview. I could only reproduce the crash when running an ad-hoc build. Here's the crash log:
Last Exception Backtrace:
0 CoreFoundation 0x30ecbe7e __exceptionPreprocess + 126
1 libobjc.A.dylib 0x3b2286c2 objc_exception_throw + 34
2 CoreFoundation 0x30ecf7b2 -[NSObject(NSObject) doesNotRecognizeSelector:] + 198
3 CoreFoundation 0x30ece0aa ___forwarding___ + 702
4 CoreFoundation 0x30e1cdc4 __forwarding_prep_0___ + 20
5 HSHacks 0x0011a368 -[FRepo initWithRepoInfo:andPersistence:] (FRepo.m:51)
6 HSHacks 0x00119b58 -[FRepoManager getLocalRepo:] (FRepoManager.m:85)
7 HSHacks 0x0011a1f0 +[FRepoManager getRepo:] (FRepoManager.m:126)
8 HSHacks 0x00132144 -[Firebase initWithUrl:] (Firebase.m:50)
9 HSHacks 0x000d0d8c -[ChatViewController viewDidLoad] (ChatViewController.m:61)
10 UIKit 0x33654956 -[UIViewController loadViewIfRequired] + 514
11 UIKit 0x33654714 -[UIViewController view] + 20
12 UIKit 0x3377bd8a -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 350
13 UIKit 0x3377bc1e -[UITabBarController transitionFromViewController:toViewController:] + 34
14 UIKit 0x3377bb2a -[UITabBarController _setSelectedViewController:] + 254
15 UIKit 0x33846840 -[UITabBarController _tabBarItemClicked:] + 268
16 UIKit 0x33684d9e -[UIApplication sendAction:to:from:forEvent:] + 86
17 UIKit 0x33684d3a -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 34
18 UIKit 0x338466f6 -[UITabBar _sendAction:withEvent:] + 366
19 UIKit 0x33684d9e -[UIApplication sendAction:to:from:forEvent:] + 86
20 UIKit 0x33684d3a -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 34
21 UIKit 0x33684d0e -[UIControl sendAction:to:forEvent:] + 42
22 UIKit 0x3367073e -[UIControl _sendActionsForEvents:withEvent:] + 370
23 UIKit 0x33684d9e -[UIApplication sendAction:to:from:forEvent:] + 86
24 UIKit 0x33684d3a -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 34
25 UIKit 0x33684d0e -[UIControl sendAction:to:forEvent:] + 42
26 UIKit 0x3367073e -[UIControl _sendActionsForEvents:withEvent:] + 370
27 UIKit 0x33684756 -[UIControl touchesEnded:withEvent:] + 590
28 UIKit 0x3364819c _UIGestureRecognizerUpdate + 5524
29 CoreFoundation 0x30e96f64 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 16
30 CoreFoundation 0x30e948f2 __CFRunLoopDoObservers + 282
31 CoreFoundation 0x30e94c3e __CFRunLoopRun + 734
32 CoreFoundation 0x30dff46c CFRunLoopRunSpecific + 520
33 CoreFoundation 0x30dff24e CFRunLoopRunInMode + 102
34 GraphicsServices 0x35b392e6 GSEventRunModal + 134
35 UIKit 0x336b4840 UIApplicationMain + 1132
36 HSHacks 0x000d7efa main (main.m:16)
37 libdyld.dylib 0x3b721ab2 tlv_initializer + 2
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x3b7d81fc __pthread_kill + 8
1 libsystem_pthread.dylib 0x3b83fa4e pthread_kill + 54
2 libsystem_c.dylib 0x3b789028 abort + 72
3 libc++abi.dylib 0x3abd798a abort_message + 70
4 libc++abi.dylib 0x3abf06e2 default_terminate_handler() + 250
5 libobjc.A.dylib 0x3b228936 _objc_terminate() + 190
6 libc++abi.dylib 0x3abee1b0 std::__terminate(void (*)()) + 76
7 libc++abi.dylib 0x3abedd12 __cxa_rethrow + 98
8 libobjc.A.dylib 0x3b22880a objc_exception_rethrow + 38
9 CoreFoundation 0x30dff4e2 CFRunLoopRunSpecific + 638
10 CoreFoundation 0x30dff24e CFRunLoopRunInMode + 102
11 GraphicsServices 0x35b392e6 GSEventRunModal + 134
12 UIKit 0x336b4840 UIApplicationMain + 1132
13 HSHacks 0x000d7efa main (main.m:16)
14 libdyld.dylib 0x3b721ab4 start + 0
Anybody have any idea what's going on?
I think it may have something to do with this code in viewDidLoad:
[self.firebase observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
// Add the chat message to the array.
[self.chat addObject:snapshot.value];
// Reload the table view so the new message will show up.
[SVProgressHUD dismiss];
[self.chatTableView reloadData];
self.chatTextField.userInteractionEnabled = TRUE;
[self.chatTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.chat.count-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}];
}