NSString sizeWithAttributes Crash on iOS 12 - objective-c

I recently encountered a strange Crash when using a lyrics component. Language is Objective-C. This stupid crash has been bothering me for many days...
Here's the code:
CGFloat charWidth = [character.character sizeWithAttributes:#{NSFontAttributeName:displayFont}].width;
and my crash log stack:
0 CoreText 0x0000000234f09938 __ZNK12TSplicedFont23GetOpticalSizeComponentEd + 148
1 CoreText 0x0000000234e7ffcc __ZL28DerivedOpticalFontDescriptorPK18__CTFontDescriptorPK9TBaseFontd + 120
2 CoreText 0x0000000234e88008 __ZN12TFontCascade26InitCascadeFallbackAtIndexElRj + 252
3 CoreText 0x0000000234e87a70 __ZNK12TFontCascade14CreateFallbackEPK8__CTFontPK10__CFString13CTEmojiPolicy + 728
4 CoreText 0x0000000234e54e40 __ZN13TGlyphEncoder21AppendUnmappedCharRunEjR6TCFRefIP5CTRunEPK8__CTFontR7CFRangeS8_R10TGlyphListI18TDeletedGlyphIndexESD_RK12TFontCascadeNS_15ClusterMatchingEb + 704
5 CoreText 0x0000000234e54900 __ZN13TGlyphEncoder28RunUnicodeEncoderRecursivelyEjO6TCFRefIP5CTRunEPK8__CTFont7CFRangeR10TGlyphListI18TDeletedGlyphIndexESC_PK12TFontCascadeNS_15ClusterMatchingEb + 1900
6 CoreText 0x0000000234e54114 __ZN13TGlyphEncoder17RunUnicodeEncoderEO6TCFRefIP5CTRunEPK8__CTFont7CFRangeR10TGlyphListI18TDeletedGlyphIndexEPK12TFontCascade + 128
7 CoreText 0x0000000234e53c30 __ZN13TGlyphEncoder11EncodeCharsE7CFRangeRK11TAttributesNS_9FallbacksE + 1240
8 CoreText 0x0000000234e6acb0 __ZN21TTypesetterAttrString10InitializeEPK20__CFAttributedString + 304
9 CoreText 0x0000000234e6ab6c __ZN21TTypesetterAttrStringC2EPK20__CFAttributedStringPK14__CFDictionary + 200
10 CoreText 0x0000000234e58070 CTLineCreateWithAttributedString + 60
11 UIFoundation 0x000000023b72be2c -[NSCoreTypesetter _stringDrawingCoreTextEngineWithOriginalString:rect:padding:context:forceClipping:styledTextOptions:attributes:stringDrawingOptions:drawingContext:wantsTextLineFragments:validatedAttributedString:firstNonRenderedCharacterIndex:foundSoftHyphenAtEOL:enginePathUsed:] + 1344
12 UIFoundation 0x000000023b7aae38 ___NSStringDrawingEngine + 3104
13 UIFoundation 0x000000023b72eb04 -[NSString(NSExtendedStringDrawing) boundingRectWithSize:options:attributes:context:] + 160
14 UIFoundation 0x000000023b7307dc -[NSString(NSStringDrawing) sizeWithAttributes:] + 120

I have fix this issue. this method must called in main thread – JethroYe

Related

Updating ObjC app on XCode 9

I recently updated our ObjC app on XCode 9. Everything was ok (I even updated to iPhone X new layout), there has been just an issue in one of the viewControllers (built in IB). This viewController, which shows a tableView with news, can be accessed from 2 sources:
From appDelegate if a Push Notification informs about new news. In this case, a right navBarButton is unhidden so the user can dismiss the view
From a specific section, where a normal back button is used
When I try to open the viewController from the second case, the app crashes with the next message:
2017-10-17 12:53:26.747396-0500 verifica[17299:1270771] * Assertion failure in -[_UIButtonBarButtonVisualProviderIOS _addConstraintsForBackgroundImageWithOffset:isBackButton:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3694.4.18/_UIButtonBarButtonVisualProviderIOS.m:485
2017-10-17 12:53:26.855489-0500 verifica[17299:1270771] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '_UIButtonBarButtonVisualProviderIOS cannot have a background without any content'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ba151cb exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010af48f41 objc_exception_throw + 48
2 CoreFoundation 0x000000010ba1a362 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000106a22089 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 UIKit 0x000000010860cd92 -[_UIButtonBarButtonVisualProviderIOS _addConstraintsForBackgroundImageWithOffset:isBackButton:] + 1079
5 UIKit 0x000000010860c903 -[_UIButtonBarButtonVisualProviderIOS _configureBackgroundForButton:fromBarButtonItem:isBackButton:] + 1060
6 UIKit 0x0000000108610610 -[_UIButtonBarButtonVisualProviderIOS configureButton:fromBarButtonItem:] + 2630
7 UIKit 0x000000010860dcaf -[_UIButtonBarButtonVisualProviderIOS configureButton:withAppearanceDelegate:fromBarItem:] + 148
8 UIKit 0x0000000107ff3096 -[_UIButtonBarButton _configureFromBarItem:appearanceDelegate:isBackButton:] + 86
9 UIKit 0x0000000107ff2c20 -[_UIButtonBarButton configureFromBarItem:withAppearanceDelegate:] + 53
10 UIKit 0x00000001085a2049 -[_UIButtonBar _updatedViewForBarButtonItem:withView:] + 338
11 UIKit 0x00000001085a0add __32-[_UIButtonBar _newGroupLayout:]_block_invoke + 82
12 UIKit 0x00000001085960d3 -[_UIButtonBarItemLayout _updateItemView] + 53
13 UIKit 0x000000010859667c -[_UIButtonBarItemLayout _configure] + 40
14 UIKit 0x000000010859518f -[_UIButtonBarLayout configure] + 60
15 UIKit 0x00000001085952d9 -[_UIButtonBarLayout addLayoutViews:] + 49
16 UIKit 0x000000010859864e -[_UIButtonBarItemGroupLayout _iterateConfiguredLayouts:] + 228
17 UIKit 0x000000010859872f -[_UIButtonBarItemGroupLayout _addLayoutViews:] + 116
18 UIKit 0x000000010859523d -[_UIButtonBarLayout addLayoutViews:layoutGuides:constraintsToActivate:constraintsToDeactivate:] + 111
19 UIKit 0x00000001085a1264 -[_UIButtonBar _layoutBar] + 1833
20 UIKit 0x00000001085a3b44 -[_UIButtonBarStackView updateConstraints] + 48
21 UIKit 0x000000010870d8b6 -[UIView(AdditionalLayoutSupport) _sendUpdateConstraintsIfNecessaryForSecondPass:] + 161
22 UIKit 0x000000010870ded2 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 1296
23 UIKit 0x000000010870dd51 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 911
24 Foundation 0x00000001069acde1 -[NSISEngine withBehaviors:performModifications:] + 131
25 UIKit 0x000000010870e703 __100-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke + 90
26 UIKit 0x000000010870cf61 -[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 104
27 UIKit 0x000000010870e272 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 160
28 UIKit 0x000000010870f38c -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:] + 401
29 UIKit 0x0000000107c671b6 -[UIView(Hierarchy) layoutBelowIfNeeded] + 1517
30 UIKit 0x00000001084a74cd -[_UINavigationBarTransitionContextPush _prepareContentView] + 130
31 UIKit 0x00000001084a8b2b -[_UINavigationBarTransitionContextPush prepare] + 133
32 UIKit 0x000000010878d15a -[_UINavigationBarVisualProviderModernIOS _performAnimationWithTransitionCompletion:transition:] + 740
33 UIKit 0x0000000107cb60b6 -[UINavigationBar _pushNavigationItem:transitionAssistant:] + 359
34 UIKit 0x0000000107cb58e2 -[UINavigationBar _pushNavigationItemUsingCurrentTransition:] + 368
35 UIKit 0x0000000107cb5a47 -[UINavigationBar pushNavigationItem:animated:] + 179
36 UIKit 0x0000000107cb02cf -[UINavigationBar _performUpdatesIgnoringLock:] + 47
37 UIKit 0x0000000107cb5b51 -[UINavigationBar _pushNavigationItem:transition:] + 152
38 UIKit 0x0000000107d97f37 __71-[UINavigationController pushViewController:transition:forceImmediate:]_block_invoke + 371
39 UIKit 0x0000000107d9812c __71-[UINavigationController pushViewController:transition:forceImmediate:]_block_invoke.1981 + 114
40 UIKit 0x0000000107d92bcf __98-[UINavigationController _shouldSkipHostedRefreshControlUpdateSchedulingDeferredUpdateIfNecessary]_block_invoke + 18
41 UIKit 0x0000000107d94b25 -[UINavigationController _startDeferredTransitionIfNeeded:] + 1343
42 UIKit 0x0000000107d95b90 -[UINavigationController __viewWillLayoutSubviews] + 115
43 UIKit 0x0000000107fec2ae -[UILayoutContainerView layoutSubviews] + 231
44 UIKit 0x0000000128bc4a9f -[UILayoutContainerViewAccessibility layoutSubviews] + 42
45 UIKit 0x0000000107c7c551 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1331
46 QuartzCore 0x000000010773a4ba -[CALayer layoutSublayers] + 153
47 QuartzCore 0x000000010773e5a9 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401
48 QuartzCore 0x00000001076c71cd _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 365
49 QuartzCore 0x00000001076f2ae4 _ZN2CA11Transaction6commitEv + 500
50 UIKit 0x0000000107bd8687 _afterCACommitHandler + 272
51 CoreFoundation 0x000000010b9b7db7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
52 CoreFoundation 0x000000010b9b7d0e __CFRunLoopDoObservers + 430
53 CoreFoundation 0x000000010b99c324 __CFRunLoopRun + 1572
54 CoreFoundation 0x000000010b99ba89 CFRunLoopRunSpecific + 409
55 GraphicsServices 0x000000010f3fd9c6 GSEventRunModal + 62
56 UIKit 0x0000000107badd30 UIApplicationMain + 159
57 verifica 0x0000000103ce9f0f main + 111
58 libdyld.dylib 0x000000010ac32d81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The app worked fine before XCode 9. I've run it in the simulator (with iOS, 10.3, 10.3.1 & 11) and on an iPhone with iOS 11, and crashes all the time for case 2.
I've searched several of the terms referred in the console, but the only similar was http://www.cocoachina.com/bbs/read.php?tid-1726269.html, I used Google Translate and one guy says: "mainly due to the navigantionBarItem picture and the location of the text caused by the offset".
As I said the view was built in IB with a normal Navigation Controller, no offset in the button. The only difference with other similar viewControllers that work fine is the right navBarButton that is shown in case 1 but not in case 2 with the next code in viewDidLoad:
if (self.fromAppDelegate) {
self.doneButton.title = #"Cerrar";
self.doneButton.enabled = YES;
} else self.doneButton.enabled = NO;
I'm sure its gonna be an easy solution but right now I can't find it. I hope someone can help me.
Update
These are this button's configuration in IB:
InterfaceBuilder: Button
OK, when I was checking the configuration for the button in IB, I noticed that its width (Size Inspector) was zero. I changed it to 80 so, the button shows now in the preview. I also, in Attributes Inspector, changed it from Custom system item to Done and in code added the next line for the else statement:
self.doneButton.title = #"";
It worked, the app didn't crash anymore, but the button, if not enabled, was visible as Done all the time which is not what I want (the code above didn't work because it was set as System Button, duh). So, I change it back to Custom and delete the default title aaaand... everything was as before (check image in the question), but the app still works. What? Well, not everything was as before: the code above was the only change. If I commented the line, the app crashes again.
I don't know if it's a bug or a new requirement, but I hope it useful for someone (I knew the answer was gonna be easy).

textViewDidChange: crashes in iOS 7

As we know the UITextView is more powerful in iOS 7, but here it performs more fragile. The following code works fine when inputting "rr" with Chinese input keyboard in iOS 6, but crashes in iOS 7.
- (void)viewDidLoad
{
[super viewDidLoad];
self.tv = [[UITextView alloc] initWithFrame:CGRectMake(0, 100, 320, 100)];
self.tv.backgroundColor = [UIColor yellowColor];
self.tv.textColor = [UIColor blackColor];
self.tv.editable = YES;
self.tv.delegate = self;
[self.view addSubview:self.tv];
}
-(void)textViewDidChange:(UITextView *)textView{
int maxLength = 2;
if (self.tv.text.length > maxLength) {
NSLog(#"self.tv.text :%#",self.tv.text);
NSLog(#"self.tv.text.length :%d",self.tv.text.length);
NSLog(#"maxLength :%d",maxLength);
self.tv.text = [self.tv.text substringToIndex:maxLength];
}
}
The log is as following:
2013-11-13 15:48:16.003 Test2[1388:70b] self.tv.text :r r
2013-11-13 15:48:16.004 Test2[1388:70b] self.tv.text.length :3
2013-11-13 15:48:16.005 Test2[1388:70b] maxLength :2
2013-11-13 15:48:16.032 Test2[1388:70b] *** Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of bounds'
*** First throw call stack:
(
0 CoreFoundation 0x017355e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014b88b6 objc_exception_throw + 44
2 CoreFoundation 0x017353bb +[NSException raise:format:] + 139
3 Foundation 0x010ebba1 -[NSMutableRLEArray replaceObjectsInRange:withObject:length:] + 136
4 Foundation 0x010ebb14 -[NSMutableRLEArray deleteObjectsInRange:] + 63
5 Foundation 0x010ea559 -[NSConcreteMutableAttributedString replaceCharactersInRange:withAttributedString:] + 324
6 UIFoundation 0x02d9d9f4 __71-[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:]_block_invoke + 68
7 UIFoundation 0x02d9d92f -[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:] + 121
8 UIKit 0x00924d22 __53-[UITextInputController setMarkedText:selectedRange:]_block_invoke + 352
9 UIFoundation 0x02d9b491 -[NSTextStorage coordinateEditing:] + 48
10 UIKit 0x00924a38 -[UITextInputController setMarkedText:selectedRange:] + 249
11 UIKit 0x008fb3b1 -[UITextView setMarkedText:selectedRange:] + 63
12 UIKit 0x00644aa5 -[UIResponder(UITextInput_Internal) _setMarkedText:selectedRange:] + 101
13 UIKit 0x004031aa -[UIKeyboardImpl setMarkedText:selectedRange:inputString:searchString:] + 365
14 UIKit 0x00419737 -[TIKeyboardOperationSetMarkedText(UIKeyboardImpl) main] + 178
15 Foundation 0x0118da69 -[__NSOperationInternal _start:] + 671
16 Foundation 0x0110a798 -[NSOperation start] + 83
17 UIKit 0x0040e08a -[UIKeyboardImpl updateCandidateDisplayAsyncWithCandidateSet:documentOperation:] + 188
18 UIKit 0x00419041 -[TIKeyboardOperationSetCandidates(UIKeyboardImpl) main] + 112
19 Foundation 0x0118da69 -[__NSOperationInternal _start:] + 671
20 Foundation 0x0110a798 -[NSOperation start] + 83
21 UIKit 0x0040671d -[UIKeyboardImpl performOperations:] + 153
22 UIKit 0x00404f4e -[UIKeyboardImpl continueGenerateCandidatesAsynchronouslyWithOperations:] + 40
23 UIKit 0x00404c51 __87-[UIKeyboardImpl replyHandlerForGenerateCandidatesAsynchronouslyWithSelectedCandidate:]_block_invoke_2 + 46
24 UIKit 0x009381b8 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 402
25 UIKit 0x0093885f -[UIKeyboardTaskQueue addTask:] + 144
26 CoreFoundation 0x01729d1d __invoking___ + 29
27 CoreFoundation 0x01729c2a -[NSInvocation invoke] + 362
28 UIKit 0x008e63d2 -[_UIActionWhenIdle invoke] + 100
29 UIKit 0x008e64a6 __41-[_UIActionWhenIdle addObserverToRunLoop]_block_invoke + 36
30 CoreFoundation 0x0172924d _runLoopObserverWithBlockContext + 29
31 CoreFoundation 0x016fd53e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
32 CoreFoundation 0x016fd48f __CFRunLoopDoObservers + 399
33 CoreFoundation 0x016db3b4 __CFRunLoopRun + 1076
34 CoreFoundation 0x016dab33 CFRunLoopRunSpecific + 467
35 CoreFoundation 0x016da94b CFRunLoopRunInMode + 123
36 GraphicsServices 0x036d69d7 GSEventRunModal + 192
37 GraphicsServices 0x036d67fe GSEventRun + 104
38 UIKit 0x0022b94b UIApplicationMain + 1225
39 Test2 0x0000388d main + 141
40 libdyld.dylib 0x01d7370d start + 1
41 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
In addition, I test the following code, it also crashes after input "rr" with Chinese input keyboard.
-(void)textViewDidChange:(UITextView *)textView{
int maxLength = 2;
if (self.tv.text.length > maxLength) {
self.tv.text = #"c";
}
}
Any help will be appreciated!
What's happening is that you're typing what is referred to as multistage text input, i.e. the input has to be confirmed from the user before it's actually committed into the underlying text. You get the crash because the text is only kind-of inputted, and until the text has been committed, it could easily change to something else.
To detect this situation, you're looking for the markedTextRange property of the UITextView, which indicates if you're in this complex input mode.
If the property is non-nil, then you're in this special input mode, so you should guard your modification code with something like:
if (self.tv.markedTextRange == nil && self.tv.text.length > maxLength) {
// Perform change
}
Near as I can tell the crash is triggered by the special multistage text input mode, so you should avoid changing the text while this mode is active.

animated circle on map with iOS 7

I am using YHAnimatedCircleView (http://yickhong-ios.blogspot.it/2012/04/animated-circle-on-mkmapview.html) to display an animated circle on a map. It works well with iOS6, while I am experiencing some problems with iOS7.
The circle appears after a long period on the map and it returns me the following error:
CoreAnimation: warning, deleted thread with uncommitted CATransaction;
0 QuartzCore 0x00fcfa96 _ZN2CA11Transaction4pushEv + 374
1 QuartzCore 0x00fcfe72 _ZN2CA11Transaction15ensure_implicitEv + 316
2 QuartzCore 0x0106791b _ZN2CA5Layer12begin_changeEPNS_11TransactionEjRP11objc_object + 37
3 QuartzCore 0x0106914e _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 290
4 QuartzCore 0x010692a9 -[CALayer setPosition:] + 68
5 QuartzCore 0x010699af -[CALayer setFrame:] + 799
6 UIKit 0x0126329c -[UIView(Geometry) setFrame:] + 302
7 UIKit 0x01361d50 -[UIImageView _setViewGeometry:forMetric:] + 210
8 UIKit 0x01361fae -[UIImageView setFrame:] + 63
9 SampleApp 0x0001d331 -[YHAnimatedCircleView drawMapRect:zoomScale:inContext:] + 1329
10 MapKit 0x00c1b8ff __43-[MKOverlayView overlay:drawKey:inContext:]_block_invoke + 847
11 MapKit 0x00c1b572 -[MKOverlayView overlay:drawKey:inContext:] + 268
12 VectorKit 0x0bff941d -[VKRasterOverlay drawKey:inContext:] + 61
13 VectorKit 0x0bff75e5 __40-[VKRasterOverlayTileSource _queueDraw:]_block_invoke + 485
14 libdispatch.dylib 0x0647d818 _dispatch_call_block_and_release + 15
15 libdispatch.dylib 0x064924b0 _dispatch_client_callout + 14
I dont know exactly what your Framework is doing but the drawing of layers shouldn't be done in the main thread. So like in this thread discussed and solved, you should just use an async-dispatcher.
dispatch_async(dispatch_get_main_queue(), ^{
[_mapView addOverlay:circle];
});
Here is an example that updated the YickHong solution for iOS7.
https://github.com/jhurray/iOS7AnimatedMapOverlay
In iOS7, you can no longer add subviews to an MKOverlay. Check out the code here and ping me if you have any questions jeff#energ.io.

IOS 6 Maps Crash

I keep getting this crash on IOS 6 but I am not sure what is wrong. Does anyone know what it means?
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: EXC_ARM_DA_ALIGN at 0x00000001
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 CoreFoundation 0x3bcab0d8 CFRetain + 20
1 CoreFoundation 0x3bd424ee __CFSetStandardRetainKey + 50
2 VectorKit 0x3840e97c -[VKAnimation _stopAnimation:] + 36
3 VectorKit 0x383d841c -[VKAnimation onTimerFired:] + 48
4 VectorKit 0x383d8240 -[VKMainLoop displayTimerFired:] + 352
5 QuartzCore 0x3664377c CA::Display::DisplayLink::dispatch(unsigned long long, unsigned long long) + 156
6 QuartzCore 0x366436d4 CA::Display::IOMFBDisplayLink::callback(__IOMobileFramebuffer*, unsigned long long, unsigned long long, unsigned long long, void*) + 60
7 IOMobileFramebuffer 0x3c497fd4 IOMobileFramebufferVsyncNotifyFunc + 152
8 IOKit 0x35a965aa IODispatchCalloutFromCFMessage + 190
9 CoreFoundation 0x3bd35888 __CFMachPortPerform + 116
10 CoreFoundation 0x3bd403e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
11 CoreFoundation 0x3bd40386 __CFRunLoopDoSource1 + 134
12 CoreFoundation 0x3bd3f20a __CFRunLoopRun + 1378
13 CoreFoundation 0x3bcb2238 CFRunLoopRunSpecific + 352
14 CoreFoundation 0x3bcb20c4 CFRunLoopRunInMode + 100
15 GraphicsServices 0x33eae336 GSEventRunModal + 70
16 UIKit 0x3be33284 UIApplicationMain + 1116
17 App Name 0x000dcb88 main (main.m:14)
18 App Name 0x000dcb54 start + 36
The application is using the MKMapkit in IOS 6.
This is an internal bug. Report this to Apple.
You may be able to use the Simulator's "Reset Content" thing (in the app/iOS Simulator menu) to clear out caches if this is happening in the Simulator.
Looks like the issue is caused by accessing a released object from within or soon after VectorKit's stopAnimation: method is called. I'm not familiar with VectorKit, so you might look in that method or what looks to be the onTimerFired: delegate callback.
Good luck.
Tim

Why application crash for "failed to resume" when using MFMailComposeViewController

My application need supporting user feedback through eMail. We prefer to use MFMailComposeViewController rather than url schema, because we need attaching some log files in the mail.
However application may crash for "failed to resume in time", when user act as follow steps.
1. Get into message editing view;
2. "Cancel-->Save Draft";
3. When saving draft, presh home button. Application will enter background state;
4. User launch application again, application will block in launch image. After few second, application will crash.
The device log said :
Jul 2 15:38:58 unknown SpringBoard[57] <Warning>: com.XXX failed to resume in time
Jul 2 15:38:58 unknown SpringBoard[57] <Warning>: Forcing crash report of XXX[461]...
Jul 2 15:38:59 unknown SpringBoard[57] <Warning>: Finished crash reporting.
Jul 2 15:38:59 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.XXX[0x8c58]) Exited: Killed: 9
Questions:
Why my application block during resume?
Why MFMailComposeViewController use so long time to save draft?
How can I walk around to avoiding crash?
Crash Report:
Date/Time: 2012-07-03 09:25:40.222 +0800
OS Version: iPhone OS 5.0.1 (9A405)
Report Version: 104
Exception Type: 00000020
Exception Codes: 0x8badf00d
Highlighted Thread: 0
Application Specific Information:
com.XXX failed to resume in time
Elapsed total CPU time (seconds): 1.720 (user 1.720, system 0.000), 17% CPU
Elapsed application CPU time (seconds): 0.009, 0% CPU
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0:
0 libsystem_kernel.dylib 0x35ca8010 0x35ca7000 + 4112
1 libsystem_kernel.dylib 0x35ca8206 0x35ca7000 + 4614
2 AppSupport 0x376c68c4 0x376b4000 + 75972
3 AppSupport 0x376c52f0 0x376b4000 + 70384
4 AppSupport 0x376c59a6 0x376b4000 + 72102
5 AppSupport 0x376c3cfc 0x376b4000 + 64764
6 AppSupport 0x376c3b8a 0x376b4000 + 64394
7 MessageUI 0x305dea90 0x305d5000 + 39568
8 MessageUI 0x306048b2 0x305d5000 + 194738
9 MessageUI 0x305f3914 0x305d5000 + 125204
10 MessageUI 0x305f2fa0 0x305d5000 + 122784
11 MessageUI 0x306025ce 0x305d5000 + 185806
12 UIKit 0x3727fcd4 0x37143000 + 1297620
13 CoreFoundation 0x33cf742e 0x33ce4000 + 78894
14 UIKit 0x371619e4 0x37143000 + 125412
15 UIKit 0x371619a0 0x37143000 + 125344
16 UIKit 0x3716197e 0x37143000 + 125310
17 UIKit 0x371616ee 0x37143000 + 124654
18 UIKit 0x37162026 0x37143000 + 127014
19 UIKit 0x37160508 0x37143000 + 120072
20 UIKit 0x3715fefa 0x37143000 + 118522
21 UIKit 0x371464e6 0x37143000 + 13542
22 UIKit 0x37145d26 0x37143000 + 11558
23 GraphicsServices 0x30578dec 0x30574000 + 19948
24 CoreFoundation 0x33d7154c 0x33ce4000 + 578892
25 CoreFoundation 0x33d714ee 0x33ce4000 + 578798
26 CoreFoundation 0x33d7033c 0x33ce4000 + 574268
27 CoreFoundation 0x33cf34d6 0x33ce4000 + 62678
28 CoreFoundation 0x33cf339e 0x33ce4000 + 62366
29 GraphicsServices 0x30577fc6 0x30574000 + 16326
30 UIKit 0x3717473c 0x37143000 + 202556
31 XXX 0x00002d26 0x1000 + 7462
32 XXX 0x00002ce4 0x1000 + 7396