I'm trying to use a simple UITextView
in a basic view, but it causes the app to crash sporadically. Sometimes it crashes while I'm typing something in it, sometimes when I'm scrolling, sometimes after I hit the return key. From the stack trace, it looks like it's being caused by graphics or animation related code for rendering UI elements for spell checking, grammar checking, etc.
Why is this crashing my app? Do I need to import additional libraries, or do I need to specify some kind of delegate for the UITextView? I literally just have a simple UITextView in a barebones view, nothing fancy.
Here's the stack trace:
Program received signal: “EXC_BAD_ACCESS”.
(gdb) bt
#0 0x9535f9b1 in ?? ()
#1 0x9534c33f in ?? ()
#2 0x9534c13e in ?? ()
#3 0x9634df5c in ?? ()
#4 0x9418d244 in CGDataProviderRetain ()
#5 0x963b7036 in ?? ()
#6 0x98263486 in CGImageReadCreateWithProvider ()
#7 0x982633a2 in CGImageSourceCreateWithDataProvider ()
#8 0x020c0947 in CGImageCreateWithPNGDataProvider ()
#9 0x02ebfeed in WKGraphicsCreateImageFromBundleWithName ()
#10 0x02ebfc3b in WebCore::GraphicsContext::drawLineForMisspellingOrBadGrammar ()
#11 0x02ebf9cb in WebCore::InlineTextBox::paintSpellingOrGrammarMarker ()
#12 0x02e73932 in WebCore::InlineTextBox::paintDocumentMarkers ()
#13 0x02e730a1 in WebCore::InlineTextBox::paint ()
#14 0x02e717ef in WebCore::InlineFlowBox::paint ()
#15 0x02e71565 in WebCore::RootInlineBox::paint ()
#16 0x02e71220 in WebCore::RenderLineBoxList::paint ()
#17 0x0354c451 in WebCore::RenderBlock::paintContents ()
#18 0x02e6d7bd in WebCore::RenderBlock::paintObject ()
#19 0x02e6ed51 in WebCore::RenderBlock::paint ()
#20 0x02e6dcf2 in WebCore::RenderBlock::paintChildren ()
#21 0x02e6d7bd in WebCore::RenderBlock::paintObject ()
#22 0x02e6ed51 in WebCore::RenderBlock::paint ()
#23 0x02e6c502 in WebCore::RenderLayer::paintLayer ()
#24 0x02e6bce3 in WebCore::RenderLayer::paintLayer ()
#25 0x02e6b635 in WebCore::RenderLayer::paint ()
#26 0x02e6b3de in WebCore::FrameView::paintContents ()
#27 0x03bd71da in -[WebFrame(WebInternal) _drawRect:contentsOnly:] ()
#28 0x03bd7104 in -[WebHTMLView drawSingleRect:] ()
#29 0x02e6af68 in _WKViewDraw ()
#30 0x02e6b03f in _WKViewDraw ()
#31 0x02e6b03f in _WKViewDraw ()
#32 0x02e6b03f in _WKViewDraw ()
#33 0x02e6b03f in _WKViewDraw ()
#34 0x02e6adb0 in WKViewDisplayRect ()
#35 0x02e6ad41 in WKWindowDrawRect ()
#36 0x02e6a9d3 in WebCore::TileCache::drawLayer ()
#37 0x04041d63 in backing_callback ()
#38 0x0404161e in CABackingStoreUpdate ()
#39 0x040407f4 in -[CALayer _display] ()
#40 0x02e6a3d4 in -[TileLayer display] ()
#41 0x040402b1 in CALayerDisplayIfNeeded ()
#42 0x0403f65b in CA::Context::commit_transaction ()
#43 0x0403f2b0 in CA::Transaction::commit ()
#44 0x04046f5b in CA::Transaction::observer_callback ()
#45 0x02391d1b in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#46 0x02326987 in __CFRunLoopDoObservers ()
#47 0x022efc17 in __CFRunLoopRun ()
#48 0x022ef280 in CFRunLoopRunSpecific ()
#49 0x022ef1a1 in CFRunLoopRunInMode ()
#50 0x02c152c8 in GSEventRunModal ()
#51 0x02c1538d in GSEventRun ()
#52 0x002e2b58 in UIApplicationMain ()
EDIT: it seems like this is indeed being caused by the autocorrection functionality, as the stack trace alludes to. If I set the "Correction" property under "Text Input Traits" in Interface Builder (I believe it's the autocorrectionType property of the UITextInputTraits protocol) to "No", then the problem goes away. With autocorrection on, I can always reproduce the bug by typing words that are misspelled.
Another thing to note is that this is with the latest iOS 4.1 SDK that I just downloaded yesterday, so I don't know if this is a UITextView bug in the latest SDK or what.
EDIT 2: Wow, I'm really stumped by this. I created a few new projects from scratch and tried to display modal view controllers with UITextViews, and they all worked with no problem. However, when I try to do the same in my actual app - no matter which controller I try to invoke a modal view controller from - it always crashes. I've boiled the code down to the barebones, and it still crashes. Here's how I initialize a modal view controller:
- (IBAction)showFeedback:(id)sender {
FooViewController *controller = [[FooViewController alloc] initWithNibName:@"FooView" bundle:nil];
[self presentModalViewController:controller animated:YES];
[controller release];
}
FooViewController is just a skeleton view controller generated by Xcode that inherits from UIViewController. Nothing is overridden. My nib file just contains an empty view with a single vanilla UITextView. Everything else is the default.
The crash always happens immediately after I type in a misspelled word, and the simulator tries to display red underlines.
I've tried running with NSZombieEnabled as well, and I don't see anything in the logs about messages being sent to zombies.
My app is pretty simple - a tab based app with navigation controllers for each of my 5 tabs. My 5 custom view controllers are then set as the root controllers of each of the navigation controllers. I currently have one of my custom view controllers create and present the modal controller. I've tried commenting out any release calls in the parent view controller, to no avail.
What I don't understand is, what objects are the graphics routines trying to access that may have been released (or not retained) that fall under my application's responsibility with respect to memory management? The only thing possible, in my mind, is the UITextView, and I've tried declaring it as a property with retain, and setting it as an outlet with Interface Builder. Still, the same crash.
Any help is greatly appreciated!!!
EXC_BAD_ACCESS basically means your accessing memory that is not in use by your App. My guess is you are editing a a variable or accessing a variable that you have already released. Comment out your releases and see how that goes.
EDIT: Could also mean you are not retaining a variable that needs to be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With