UITextView textViewShouldBeginEditing crashes when tapped more than once - iphone

I have a UIViewController. In this controller I programmatically create a UITextView and set its delegate as my controller. I do this because I dont want to start editing the textView when I tap it.
ViewDidLoad method
UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(9, 10, 302, 200)];
[textView setDelegate:self];
[self.view addSubview:textView];
[textView release];
I implemented the textViewShouldBeginEditing method to return NO here to disable the keyboard from showing up.
textViewShouldBeginEditing method
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
NSLog(#"Shouldbegin");
return NO;
}
The problem that appears
When I tap the textView it works once, but if i tap it again it will crash the application without any log. The weird thing when I hold the textView and release it, it will work like I want it to work. A normal single tap on the other hand doesn't work a second time.
Edit
Single tapping quickly after each other also seems to work, so it seems that it wont work after i wait x seconds.
After some testing I found out it seems to be an iOS 5.X > bug. When running my App in a 4.3 device/simulator it works like it should. The error log on a iOS 5.1 device says the following:
Date/Time: 2012-04-17 14:00:49.497 +0200
OS Version: iPhone OS 5.1 (9B176)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000014
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 TextInput 0x36bf69e8 TI::Favonius::BeamSearch::choose_hit_test_node(WTF::RefPtr<TI::Favonius::SearchNode> const&, WTF::RefPtr<TI::Favonius::KeyAreaNode> const&, WTF::RefPtr<TI::Favonius::SearchNode> const&, WTF::RefPtr<TI::Favonius::SearchNode> const&) + 12
1 TextInput 0x36bf6d1e TI::Favonius::BeamSearch::update_for_touch(unsigned int, WTF::PassRefPtr<TI::Favonius::KeyAreaNode>) + 602
2 TextInput 0x36bfb5c2 TI::Favonius::StrokeBuildManager::update_search_for_touch(unsigned int, int) + 66
3 TextInput 0x36bfb97c TI::Favonius::StrokeBuildManager::key_down_or_drag_hit_test_for_UI(bool, CGPoint, double, int, int, float, bool, ZT::LayoutDictionaryContext&, bool, int) + 216
4 TextInput 0x36bddf54 TIInputManagerZephyr::simulate_touches_for_input_string() + 344
5 TextInput 0x36bed8ba -[TIKeyboardInputManagerZephyr candidates] + 214
6 UIKit 0x31066616 -[UIKeyboardImpl generateAutocorrectionReplacements:] + 82
7 UIKit 0x31108a96 __71-[UITextInteractionAssistant scheduleReplacementsForRange:withOptions:]_block_invoke_0 + 370
8 UIKit 0x3110ec62 -[UITextSelectionView calculateAndShowReplacements:] + 6
9 Foundation 0x3762192c __NSFireDelayedPerform + 408
10 CoreFoundation 0x361a1a2c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
11 CoreFoundation 0x361a1692 __CFRunLoopDoTimer + 358
12 CoreFoundation 0x361a0268 __CFRunLoopRun + 1200
13 CoreFoundation 0x3612349e CFRunLoopRunSpecific + 294
14 CoreFoundation 0x36123366 CFRunLoopRunInMode + 98
15 GraphicsServices 0x324e3432 GSEventRunModal + 130
16 UIKit 0x30e70e76 UIApplicationMain + 1074

I did find a solution. I don't really like working around Apple bugs but sometimes you have to. It is three steps...
1) replace the default keyboard with an invisible view
- (void)viewDidLoad
{
[super viewDidLoad];
myTextView.inputView = customKeyboard;
}
2) answer YES to allow editing
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
return YES;
}
3) In textViewDidChangeSelection resign the first responder to hide the cursor
- (void)textViewDidChangeSelection:(UITextView *)textView{
[textView resignFirstResponder];
}

If you don't want to start editing of UITextView when you tapped it:
UITextView* textView = ...;
textView.editable = NO;

After some testing I found out it seems to be an iOS 5.X > bug. When running my App in a 4.3 device/simulator it works like it should.
Look in my main post where i edited the logfile.

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
[txtView resignFirstResponder];
}
and release txtView in dealloc method

Swift 4.2
The best and easy way to solve this just make undo manager as false
textView.undoManager?.disableUndoRegistration()
This error appears if you have change the view at run time like within the table, and cell will be reloaded on tapping,

Related

iOS crash: respondsToSelector: message sent to deallocated instance

I am using a UINavigationController as rootviewController and storyboard segue for pushingViewController. I have many viewcontrollers in my app. I pass them using push view controller only.
Crash scenario: (can reproduce)
I have a Products list viewController and I will navigate to products detail viewController when I tap on product in the list using tap Gesture recognizer.
From the detail view controller, I will be pushed to cart item viewController which displays all selected products when I tap a button named 'Addd to cart'.
If I try to pay for all the products I want to choose a contact from the people picker, when I press pay button, it will present peopelpickerController as modalViewController and when I choose a contact it gets crashed.
Crash occurs only when move to and fro from products list view controlelr to peoplepicker contoller. When I debugged using instrument I got crash saying deallocated instance receiving message.
I have included the method where I am getting crash. But i never tried to call the method from any controller.
Code...
//choosing contact and people picker delegate
- (IBAction) chooseContacts: (id) sender {
picker = [
[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentViewController: picker animated: YES completion: nil];
}
#pragma mark - Addressbook delegate methods
- (void) peoplePickerNavigationControllerDidCancel: (ABPeoplePickerNavigationController * ) peoplePicker {
[self dismissViewControllerAnimated: YES completion: nil];
}
- (BOOL) peoplePickerNavigationController: (ABPeoplePickerNavigationController * ) peoplePicker
shouldContinueAfterSelectingPerson: (ABRecordRef) person {
[self dismissViewControllerAnimated: YES completion: ^ {
[self displayPerson: person];
}];
return NO;
}
Crash occurs in the below method at the line performSegueWithIdentifier,
#pragma mark- Tap gesture delegates
-(void)tapGestureFirstImage:(UITapGestureRecognizer *)sender
{
UIImageView *image = (UIImageView *)sender.view;
if (image.tag < [_productsArray count]) {
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
productDetailDictionary = [_productsArray objectAtIndex:image.tag];
NSLog(#"%#",productDetailDictionary);
[self performSegueWithIdentifier:#"productDetailSeague" sender:sender];
}
NSLog(#"imageView.Tag %ld",(long)image.tag);
}
Crash Log:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 0
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x39cb11fc __pthread_kill + 8
1 libsystem_pthread.dylib 0x39d1aa2e pthread_kill + 54
2 libsystem_c.dylib 0x39c61ff8 abort + 72
3 libc++abi.dylib 0x38f90cd2 abort_message + 70
4 libc++abi.dylib 0x38fa96e0 default_terminate_handler() + 248
5 libobjc.A.dylib 0x396f291e _objc_terminate() + 190
6 libc++abi.dylib 0x38fa71c4 std::__terminate(void (*)()) + 76
7 libc++abi.dylib 0x38fa6a18 __cxa_throw + 112
8 libobjc.A.dylib 0x396f277e objc_exception_throw + 246
9 CoreFoundation 0x2ef5be88 +[NSException raise:format:] + 100
10 UIKit 0x317b9590 -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:] + 496
11 UIKit 0x317b7dce -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 2054
12 UIKit 0x317b6e20 -[UIViewController presentViewController:withTransition:completion:] + 4664
13 UIKit 0x31992cae -[UIViewController presentModalViewController:animated:] + 26
14 DHCC Events 0x0008f0c0 0x38000 + 356544
15 libdispatch.dylib 0x39bd5d18 _dispatch_call_block_and_release + 8
16 libdispatch.dylib 0x39bdbd16 _dispatch_after_timer_callback$VARIANT$mp + 46
17 libdispatch.dylib 0x39bd5d04 _dispatch_client_callout + 20
18 libdispatch.dylib 0x39bde7fe _dispatch_source_invoke$VARIANT$mp + 258
19 libdispatch.dylib 0x39bdc73a _dispatch_main_queue_callback_4CF$VARIANT$mp + 186
20 CoreFoundation 0x2ef26814 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 4
21 CoreFoundation 0x2ef250e8 __CFRunLoopRun + 1296
22 CoreFoundation 0x2ee8fc22 CFRunLoopRunSpecific + 518
23 CoreFoundation 0x2ee8fa06 CFRunLoopRunInMode + 102
24 GraphicsServices 0x33b8327e GSEventRunModal + 134
25 UIKit 0x31733044 UIApplicationMain + 1132
26 DHCC Events 0x00041ad6 0x38000 + 39638
27 libdyld.dylib 0x39bfaab4 start + 0
Appreciate your help.
On -(void)tapGestureFirstImage:(UITapGestureRecognizer *)sender
you perform the segue with
[self performSegueWithIdentifier:#"productDetailSeague" sender:sender];
but I think the sender should be self and not sender..
UPDATE
Do you try to perform segue while picker is active? In this case self may be deallocated, so you can try to perform segue after picker is dismissed:
[picker dismissViewControllerAnimated:YES completion:^{[self performSegueWithIdentifier:#"productDetailSeague" sender:self];}];

NSInvalidArgumentException - touchBackgroundLogin

I'm using a keyboard and I've just implement this method to hide the keyboard when "done" is pressed :
-(IBAction) finEdition: (id)sender{
[sender resignFirstResponder];
}
Here is the stack trace :
2012-01-10 11:44:33.949 emars[27985:b303] -[ThirdViewController touchBackgroundLogin:]: unrecognized selector sent to instance 0x682fa00
2012-01-10 11:44:33.990 emars[27985:b303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ThirdViewController touchBackgroundLogin:]: unrecognized selector sent to instance 0x682fa00'
*** Call stack at first throw:
(
0 CoreFoundation 0x00fb55a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01109313 objc_exception_throw + 44
2 CoreFoundation 0x00fb70bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00f26966 ___forwarding___ + 966
4 CoreFoundation 0x00f26522 _CF_forwarding_prep_0 + 50
5 UIKit 0x002c64fd -[UIApplication sendAction:to:from:forEvent:] + 119
6 UIKit 0x00356799 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00358c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
8 UIKit 0x00357a1c -[UIControl touchesBegan:withEvent:] + 277
9 UIKit 0x002ead41 -[UIWindow _sendTouchesForEvent:] + 395
10 UIKit 0x002cbc37 -[UIApplication sendEvent:] + 447
11 UIKit 0x002d0f2e _UIApplicationHandleEvent + 7576
12 GraphicsServices 0x01891992 PurpleEventCallback + 1550
13 CoreFoundation 0x00f96944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
14 CoreFoundation 0x00ef6cf7 __CFRunLoopDoSource1 + 215
15 CoreFoundation 0x00ef3f83 __CFRunLoopRun + 979
-(IBAction) finEdition: (id)sender is method for Button not for textfield [sender resignFirstResponder];sender is id of Button/ViewController try to resign first responder so application get crashed
-(IBAction) finEdition: (id)sender
{
[self.textfield1 resignFirstResponder];
[self.textfield2 resignFirstResponder];
...
...
...
[self.textfieldn resignFirstResponder];
}
//here this is delegate method of UITextField so you can use [theTextField resignFirstResponder];
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
[theTextField resignFirstResponder];
return YES;
}
It is your application’s responsibility to dismiss the keyboard at the time of your choosing. You might dismiss the keyboard in response to a specific user action, such as the user tapping a particular button in your user interface. You might also configure your text field delegate to dismiss the keyboard when the user presses the “return” key on the keyboard itself. To dismiss the keyboard, send the resignFirstResponder message to the text field that is currently the first responder. Doing so causes the text field object to end the current editing session (with the delegate object’s consent) and hide the keyboard.
So, you have to send resignFirstResponder somehow. But there is a possibility that textfield loses focus another way during processing of textFieldShouldReturn: message. This also will cause keyboard to disappear.
Make sure you're setting your view/viewcontroller to be the UITextField's delegate after you init the textfield in the .m:
yourTextField.delegate = self;

iPhone: SIGSEGV occurs seemingly randomly (ViewDidLoad, setFont, etc.) on device, never in simulator

First, thanks in advance for taking the time to read through this. I have been searching for an answer to this issue for a few days but I cannot seem to find what I am looking for. I know that SIGSEGV errors (or EXEC_BAD_ACCESS faults) are usually caused by memory management issues but after hours of looking at the code, I can't seem to find an error. The static analyzer hasn't found anything either.
As the title says, this error only occurs on the device (never in the simulator) and doesn't happen every time the given view loads. Obviously this means that I can't use NSZombie to debug what is going wrong.
Let's start with the crash dump log:
0 myApp 0x00036659 +[TFCrashHandler backtrace] + 428
1 myApp 0x00036a6f TFSignalHandler + 54
2 libsystem_c.dylib 0x32f48539 _sigtramp + 48
3 UIKit 0x365701df -[UIView(Rendering) setNeedsDisplay] + 86
4 UIKit 0x36598269 -[UILabel setFont:] + 232
5 myApp 0x000190eb +[BruUISettings applyLabelDetailStyle:] (BruUISettings.m:130)
6 myApp 0x0001aa57 -[ActiveChallengeViewController viewDidLoad] (ActiveChallengeViewController.m:115)
7 UIKit 0x365a57ff -[UIViewController view] + 166
8 UIKit 0x365b1c39 -[UIViewController contentScrollView] + 24
9 UIKit 0x365b1aa9 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 36
10 UIKit 0x365b198f -[UINavigationController _layoutViewController:] + 34
11 UIKit 0x365b115b -[UINavigationController _startTransition:fromViewController:toViewController:] + 318
12 UIKit 0x365b0f53 -[UINavigationController _startDeferredTransitionIfNeeded] + 250
13 UIKit 0x365a5673 -[UINavigationController pushViewController:transition:forceImmediate:] + 806
14 UIKit 0x365a5349 -[UINavigationController pushViewController:animated:] + 36
15 myApp 0x00015dc7 -[ChallengesHomeViewController tableView:didSelectRowAtIndexPath:] (ChallengesHomeViewController.m:325)
16 UIKit 0x3661f565 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 944
17 UIKit 0x36697ce7 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 158
18 Foundation 0x31f7a943 __NSFireDelayedPerform + 414
19 CoreFoundation 0x34ab1a63 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
20 CoreFoundation 0x34ab16c9 __CFRunLoopDoTimer + 364
21 CoreFoundation 0x34ab029f __CFRunLoopRun + 1206
22 CoreFoundation 0x34a334dd CFRunLoopRunSpecific + 300
23 CoreFoundation 0x34a333a5 CFRunLoopRunInMode + 104
24 GraphicsServices 0x351a7fed GSEventRunModal + 156
25 UIKit 0x3659a743 UIApplicationMain + 1090
26 myApp 0x000026c5 main (main.m:13)
27 myApp 0x0000265c start + 52
Note, I am using TestFlight from testflightapp.com and it is there exception handler at the top of the stack.
Here is the code that is creating and pushing the view controller in question:
CDAcceptedChallenge *challengeAtIndex = [self.activeChallenges objectAtIndex:[indexPath row]];
ActiveChallengeViewController *view = [[ActiveChallengeViewController alloc] initWithNibName:#"ActiveChallengeViewController"
bundle:nil
activeChallenge:challengeAtIndex];
view.leaveChallengeTarget = self;
[self.navigationController pushViewController:view animated:YES];
[view release];
This code is running inside of a didSelectRowAtIndex method, if that matters at all. This view controller has a bunch of member variables and IBOutlets which reference objects in the nib but here are the ones that correlate to the object mentioned in this error:
in .h:
UILabel *helpLabel;
...
#property (nonatomic, retain) IBOutlet UILabel *helpLabel;
in .m:
#synthesize helpLabel;
I am positive that helpLabel is bound to the correct object in the nib because it does get the correct styling when this doesn't blow up. Next, here is the init method for this view controller:
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
self.activeChallenge = inActiveChallenge;
}
return self;
Here is the viewDidLoad method where we will sometimes see the crash (bolded). Note, there is a lot going on here but nothing touches the self.helpLabel which is what eventually triggers the crash.
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:FALSE];
self.navigationItem.title = #"Details";
// overlay disclosure creation
self.overlayDisclosure = [CustomColoredDisclosureIndicator accessoryWithColor:self.challengeNameLabel.textColor];
self.overlayDisclosure.highlightedColor = [UIColor whiteColor];
[self.overlayDisclosure addTarget:self action:#selector(overlayViewButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.overlayDisclosure];
[[BruNotificationManager instance] registerForTabUpdated:[[[BruCallback alloc] initWithTarget:self
andCallback:#selector(tabUpdated:)] autorelease]];
[[BruNotificationManager instance] registerForActiveChallengesUpdated:[BruCallback buildFromObject:self
andCallback:#selector(challengesUpdatedLocally)]];
[[BruNotificationManager instance] registerForEarnedRewardsUpdated:[BruCallback buildFromObject:self
andCallback:#selector(rewardsUpdatedLocally:)]];
[super refreshEarnedRewardsForChallenge:self.activeChallenge.challenge.identifier];
[super refreshTabForChallenge:self.activeChallenge.challenge.identifier];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:#selector(addBeer)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
// Request that the object download its image
BruCallback *imageCallback = [BruCallback buildFromObject:self andCallback:#selector(imageRequestCompleted:withData:)];
self.challengeImageView.image = [self.activeChallenge.challenge retrieveImage:self.bruConnection withCallback:imageCallback];
// Create our help label
**[BruUISettings applyLabelDetailStyle:self.helpLabel];**
self.helpLabel.textColor = AccentSecondaryColor;
self.overlayView.alpha = [BruUISettings standardOverlayViewAlpha];
[BruUISettings applyTableStyle:self.rewardsTable];
[BruUISettings applyScrollViewStyle:self.scrollView];
self.needToUpdateTab = YES;
self.needToUpdateRewards = YES;
self.needToUpdateChallenge = NO;
Here is a trimmed down version of the viewDidUnload method, though I don't see why it would matter in this case:
...
self.helpLabel = nil;
...
[super viewDidUnload];
Finally, my [BruUISettings applyLabelDetailStyle] is a method that applies a centralized style to my label. There are a bunch of places in my code that use this function so that I can change all of the styles for those labels by just changing the one function.
+ (void) applyLabelDetailStyle:(UILabel *)inLabel
{
inLabel.font = [UIFont fontWithName:#"Helvetica Neue" size:12.0];
inLabel.textColor = [UIColor darkGrayColor];
inLabel.backgroundColor = [UIColor clearColor];
}
Any thoughts as to what could be happening here would be greatly appreciated. Thanks again.
After a lot of debugging I found that this was actually due to a memory corruption being caused by the QSStrings library which I was using to generate base64 encoded strings. The crashes seemed to happen randomly but only after this library was invoked. When I switched to a different MD5 library, the issue went away. If you are using this library, I would suggest finding a new one to do base64 encoding. I moved to the one found here: http://www.cocoadev.com/index.pl?BaseSixtyFour
I think the problem happens because you have something wrong in your view that owns your label (view of your ActiveChallengeViewController).
When you set the font of your label, that invokes the setNeedsDisplay of your parent view and because something is wrong, setNeedsDisplay crashs.
Your line :
self.challengeImageView.image = [self.activeChallenge.challenge retrieveImage:self.bruConnection withCallback:imageCallback];
Is it a synchronous connection to retrieve the image ?
Maybe the problem happen here when sometimes the image isn't retrieved from your connection and so the image property of your image view is bad.
But i am not sure because setNeedsDisplay doesn't directly invoke the redraw of the view so i don't know if the debugger catches the error just the after setNeedsDisplay call.
Edit :
I think this answer is bad, if image is not ok, the crash must happen when the imageView image property retains the image but i let the answer in the case of it could help you to point to the real problem.

UIWebView loading html5-Video EXC_BAD_ACCESS crash

in our iPad-App we are using an UIWebView to load different sites from one domain some of them with a hml5-Video.
Sites without a Video do load perfectly. But when I'm loading a site containing htmlt5-video sometimes my app
crashes during the loading-process of the UIWebView with EXC_BAD_ACCESS and sometimes it does not. Whenever such a crash occurs it seems to happen at the point where the Video-Player is added into the site.
I did download the UICatalog-Example from Apple and just did change the Default-URL in the WebViewController-Class to a URL of a site containg html5-video. Same results ... sometimes crash sometimes no crash.
I also did create a New Project on Xcode (View-based Application - for iPad) and only did add a UIWebView to the new Projects ViewController. Again ... loading a site containing html5-video sometimes leads to a crash and sometimes not.
CODE FROM "NEW PROJECTS" VIEWCONTROLLER (IMPLEMENTATION):
- (void)viewDidLoad {
[super viewDidLoad];
self.myWebView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)] autorelease];
self.myWebView.backgroundColor = [UIColor whiteColor];
self.myWebView.scalesPageToFit = YES;
self.myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.myWebView.delegate = self;
[self.view addSubview: self.myWebView];
[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.gelbeseiten.de/129103114849"]]];
//More Sites with HTML5-Videos ...
//[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.gelbeseiten.de/129103746403"]]];
//[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.gelbeseiten.de/129105233646"]]];
}
- (void)viewDidUnload {
[super viewDidUnload];
self.myWebView = nil;
}
- (void)viewWillDisappear:(BOOL)animated {
[self.myWebView stopLoading];
}
- (void)dealloc {
myWebView.delegate = nil;
[myWebView release];
[super dealloc];
}
CODE FROM "NEW PROJECTS" VIEWCONTROLLER (HEADER):
#interface WebViewTestViewController : UIViewController <UIWebViewDelegate> {
UIWebView *myWebView;
}
#property (nonatomic, retain) UIWebView *myWebView;
DEVICE LOGS:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000098
Crashed Thread: 0
Thread 0 Crashed:
0 WebCore 0x34c7d09e WebCore::RenderLayer::clippingRoot() const + 110
1 WebCore 0x34c7cf2a WebCore::RenderLayer::childrenClipRect() const + 26
2 WebCore 0x34c7ce0c WebCore::RenderWidget::setWidgetGeometry(WebCore::IntRect const&) + 40
3 WebCore 0x34c5e0f8 WebCore::RenderWidget::updateWidgetPosition() + 320
4 WebCore 0x34ba0170 WebCore::RenderView::updateWidgetPositions() + 144
5 WebCore 0x34b97d16 WebCore::FrameView::performPostLayoutTasks() + 202
6 WebCore 0x34b8a6c0 WebCore::FrameView::layout(bool) + 2116
7 WebCore 0x34bc5244 WebCore::FrameView::forceLayout(bool) + 4
8 WebKit 0x302c0c24 -[WebHTMLView layoutToMinimumPageWidth:height:maximumPageWidth:adjustingViewSize:] + 136
9 WebKit 0x302c0b8e -[WebHTMLView layout] + 18
10 WebKit 0x302c26f2 -[WebHTMLView(WebInternal) _layoutIfNeeded] + 50
11 WebKit 0x302c2622 -[WebHTMLView(WebInternal) _web_layoutIfNeededRecursive] + 14
12 WebKit 0x302c251e -[WebHTMLView(WebPrivate) viewWillDraw] + 50
13 CoreFoundation 0x3581dfc0 -[NSObject(NSObject) performSelector:] + 12
14 CoreFoundation 0x35826d4a -[NSArray makeObjectsPerformSelector:] + 382
15 WebCore 0x34bb000c -[WAKView viewWillDraw] + 24
16 CoreFoundation 0x3581dfc0 -[NSObject(NSObject) performSelector:] + 12
17 CoreFoundation 0x35826d4a -[NSArray makeObjectsPerformSelector:] + 382
18 WebCore 0x34bb000c -[WAKView viewWillDraw] + 24
19 CoreFoundation 0x3581dfc0 -[NSObject(NSObject) performSelector:] + 12
20 CoreFoundation 0x35826d4a -[NSArray makeObjectsPerformSelector:] + 382
21 WebCore 0x34bb000c -[WAKView viewWillDraw] + 24
22 CoreFoundation 0x3581dfc0 -[NSObject(NSObject) performSelector:] + 12
23 CoreFoundation 0x35826d4a -[NSArray makeObjectsPerformSelector:] + 382
24 WebCore 0x34bb000c -[WAKView viewWillDraw] + 24
25 WebKit 0x302c24cc -[WebView(WebPrivate) viewWillDraw] + 56
26 WebCore 0x34bafec0 WebCore::TileCache::prepareToDraw() + 36
27 WebCore 0x34bafe6e -[TileLayer display] + 26
28 QuartzCore 0x31079fb0 CALayerDisplayIfNeeded + 176
29 QuartzCore 0x3106f56e CA::Context::commit_transaction(CA::Transaction*) + 214
30 QuartzCore 0x3106f37c CA::Transaction::commit() + 184
31 QuartzCore 0x31092f96 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 46
32 CoreFoundation 0x3580ac52 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 10
33 CoreFoundation 0x3580aac6 __CFRunLoopDoObservers + 406
34 CoreFoundation 0x358020c4 __CFRunLoopRun + 848
35 CoreFoundation 0x35801c80 CFRunLoopRunSpecific + 224
36 CoreFoundation 0x35801b88 CFRunLoopRunInMode + 52
37 GraphicsServices 0x320c84a4 GSEventRunModal + 108
38 GraphicsServices 0x320c8550 GSEventRun + 56
39 UIKit 0x341dc322 -[UIApplication _run] + 406
40 UIKit 0x341d9e8c UIApplicationMain + 664
41 WebViewTest 0x00002c24 0x1000 + 7204
42 WebViewTest 0x00002bd8 0x1000 + 7128
Can anybody give me an idea?
Thanks in advance, Florian
There is a little trick to override this crash. If you slightly scroll the webview just before the video content is loaded, the crash can be avoided. Before trying it out from code, try scrolling the webView a bit on device with your finger. It won't crash now.
In code, do something like this:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:#"window.scrollTo(0, 10);"];
}
to simulate a scroll on the webview through javascript. The scroll value can be as low as 1, so the user won't notice the scroll at all.
Telling the webview to evaluate any JavaScript (or none at all) on webViewDidFinishLoad: seems work (albeit hacky).
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:#""];
}
Seems I've solved this issue...
i've moved all HTML-5 video tags insertion in Javascript
function placeVideoTag() {
var val = '<video />';
var el = document.getElementById('video-id');
el.innerHTML = val;
}
And i'm calling JS in [UIWebView didFinishLoad]
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
[aWebView stringByEvaluatingJavaScriptFromString:#"placeVideoTag()"];
}
Works perfectly in my case.
Other suggestions didn't work for me.
I have exactly the same problem. no answer yet. Saw many others reports similar problems - iOS 4.2.1 only.
Basically, I have a UIView Controller with a webview as its subview, and load a URLRequest to a youtube link.
The first time I load the viewController, the console logs error "Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/System/Library/Internet Plug-Ins/QuickTime Plugin.webplugin/QuickTime Plugin (file not found).". I stop loading and release the viewController. The second time I re-load new viewController with the same request to that youtube link, now the app crashed with EXC_BAD_ACCESS
Thanks, for your posts!!! In my case it only works with different quite high offset-values for Portrait- and Landscape-Mode on iPad
(Portrait-Mode: greater than 60; Landscape-Mode: greater than 780):
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if (self.interfaceOrientation == UIInterfaceOrientationPortrait ||
self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[webView stringByEvaluatingJavaScriptFromString:#"window.scrollTo(0, 60);"];
} else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[webView stringByEvaluatingJavaScriptFromString:#"window.scrollTo(0, 780);"];
}
webView.loadCounter--;
}
But with this solution my app crashes by double-tapping to zoom during the loading-process of a site.
I did subclass UIWebView to solve this problem (to prevent webView from zooming while loading):
.m:
#synthesize loadCounter;
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
CGPoint p = currentPoint;
NSTimeInterval t = currentTimestamp;
currentPoint = point;
currentTimestamp = [event timestamp];
if (CGPointEqualToPoint(p, point) &&
[event timestamp] - t < 0.2 && loadCounter > 0){
return self.superview;
}
return [super hitTest:point withEvent:event];
}
.h:
#interface NonDoubleTapableWhileLoadingWebView : UIWebView {
CGPoint currentPoint;
NSTimeInterval currentTimestamp;
NSInteger loadCounter;
}
#property (assign) NSInteger loadCounter;
And added a counter to determine the last "didFinish"-call and to reactivate the double-tapping possibility
(init loadCounter with 0)
- (void)webViewDidStartLoad:(UIWebView *)webView {
linkWebView.loadCounter++;
}

Crash presenting modal view controller

I have this crash. It is similar to other threads, but not the same.
I would like to show a modal view controller first the user goes to a specific view controller. Following the hints, I do that on - (void) viewDidAppear:(BOOL)animated, and apply a delay as I saw it's recommended.
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSelector:#selector(presentMyModal) withObject:nil afterDelay:1];
}
- (void) presentModal{
ModalViewController *modal = [[[ModalViewController alloc] init] autorelease];
[self presentModalViewController:modal animated:YES];
}
Afterwards, ramdomly It crashes. I get this message in console:
<Warning>: *** Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:], /SourceCache/UIKit/UIKit-1447.6.4/UIWindowController.m:186
Thu Feb 3 10:00:44 unknown MyApp[1830] <Error>: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal transition from <UINavigationController: 0x454260> to <ModalViewController: 0x47af00> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed'
*** Call stack at first throw:
(
0 CoreFoundation 0x3759dc7b __exceptionPreprocess + 114
1 libobjc.A.dylib 0x32d9bee8 objc_exception_throw + 40
2 CoreFoundation 0x3759dac3 +[NSException raise:format:arguments:] + 70
3 Foundation 0x351a3e73 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62
4 UIKit 0x359e92a8 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 208
5 UIKit 0x359e8c98 -[UIViewController presentModalViewController:withTransition:] + 2792
6 UIKit 0x35a7b51c -[UIViewController _tryRecursivelyPresentModalViewController:withTransition:] + 116
7 UIKit 0x359e84c0 -[UIViewController presentModalViewController:withTransition:] + 784
8 UIKit 0x359e8060 -[UIViewController presentModalViewController:animated:] + 96
9 MyApp 0x0005d57f -[MyAppViewController presentMyModal] + 58
10 Foundation 0x351724db __NSFireDelayedPerform + 366
11 CoreFoundation 0x37552305 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 16
12 CoreFoundation 0x37551cd9 __CFRunLoopDoTimer + 988
13 CoreFoundation 0x37521a91 __CFRunLoopRun + 1184
14 CoreFoundation 0x3752150b CFRunLoopRunSpecific + 226
15 CoreFoundation 0x37521419 CFRunLoopRunInMode + 60
16 GraphicsServices 0x33e76d24 GSEventRunModal + 196
17 UIKit 0x3591d57c -[UIApplication _run] + 588
18 UIKit 0x3591a558 UIApplicationMain + 972
19 MyApp 0x0000e75f main + 50
20 MyApp 0x0000e6e8 start + 52
As you can see, I wait until view is appeared. Is this maybe an OS bug? It seems like it tries to present recursively other modal view controllers, provoquing crashes.
Thanks a lot.
Apart from me being picky in the comment, I thought I could as well help with this one as well. I think you need to search for the culprit somewhere else. I created a new project and a view controller with this snippet:
#import "VC1.h"
#implementation VC1
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self performSelector:#selector(presentModal) withObject:nil afterDelay:1.0];
}
- (void)presentModal {
static int colorChooser = 0;
VC1 *vc1 = [[[VC1 alloc] init] autorelease];
switch (colorChooser%2) {
case 0:
vc1.view.backgroundColor = [UIColor whiteColor];
break;
default:
vc1.view.backgroundColor = [UIColor blackColor];
break;
}
colorChooser++;
[self presentModalViewController:vc1 animated:YES];
}
#end
And it works flawlessly after being pushed on the navigation controller. It is recursively alternating between black and white views, tested both in the sim and on a 3G device.
Maybe you are doing some other view transitions due to some notifications or other asynchronic means? Either way you would need to share more of your code for anyone to tell where the problem is.
Our preferred solution is to use -[UIViewController presentViewController:animated:completion:] and do whatever the next action is (eg presenting another VC) in the completion block.
For example:
[self presentViewController:yourViewController animated:YES completion:^{
[yourViewController presentMyModal];
}];
This method was introduced in iOS 5.0.