I have a strange error, i created an UIBarButtonItem programatically, it works fine on simulator and on device when its connected to Xcode. But whenever i unplug the device, the app crashes when i touch the button.
Here is how i create the button, and assign it to the navigation bar:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(backToMainPage:)];
Method:
- (void)backToMainPage:(id)sender
{
NSLog(#"...");
}
This is the error i got:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x40290020
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x3693d386 _ZL12realizeClassP7class_t + 34
1 libobjc.A.dylib 0x3693d3e6 _ZL12realizeClassP7class_t + 130
2 libobjc.A.dylib 0x36937836 prepareForMethodLookup + 74
3 libobjc.A.dylib 0x36937740 lookUpMethod + 40
4 libobjc.A.dylib 0x3693770c _class_lookupMethodAndLoadCache3 + 12
5 libobjc.A.dylib 0x36936fc4 objc_msgSend_uncached + 20
6 UIKit 0x30f28fa8 -[UIApplication sendAction:to:from:forEvent:] + 56
7 UIKit 0x30f28f64 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 24
8 UIKit 0x30f28f42 -[UIControl sendAction:to:forEvent:] + 38
9 UIKit 0x30f28cb2 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 486
10 UIKit 0x30f295ea -[UIControl touchesEnded:withEvent:] + 470
11 UIKit 0x30f27acc -[UIWindow _sendTouchesForEvent:] + 312
12 UIKit 0x30f274ba -[UIWindow sendEvent:] + 374
13 UIKit 0x30f0d836 -[UIApplication sendEvent:] + 350
14 UIKit 0x30f0d0dc _UIApplicationHandleEvent + 5820
15 GraphicsServices 0x33f30224 PurpleEventCallback + 876
16 CoreFoundation 0x3494251c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
17 CoreFoundation 0x349424be __CFRunLoopDoSource1 + 134
18 CoreFoundation 0x3494130c __CFRunLoopRun + 1364
19 CoreFoundation 0x348c449e CFRunLoopRunSpecific + 294
20 CoreFoundation 0x348c4366 CFRunLoopRunInMode + 98
21 GraphicsServices 0x33f2f432 GSEventRunModal + 130
22 UIKit 0x30f3be76 UIApplicationMain + 1074
Can anyone help me what i did wrong?
Thanks in advance!
I would imagine that the viewcontroller gets released. Could you show where this viewcotroller is created and how its view gets on screen.
There is no garbage collection. The difference might be that in a debug setting objects get retained indefinitely for better logging
Try this
UIBarButtonItem *barButton = [[[UIBarButtonItem alloc]initWithImage:infoButton.currentImage style:UIBarButtonItemStyleBordered target:self action:#selector(showInfo:)] autorelease];
[self.navigationItem setLeftBarButtonItem:barButton];
Thanks :)
Related
here is my problem:
I have a fully working app which runs quite perfect on my iPhone 4S running iOS 5.1.1.
Now Apple rejected my app because they found that the app crashed upon launch on iPhone 4 running iOS 5.1.1. What do I have to do to compile for the iPhone 4? I can't really test it because I only have an iPhone 4S to my disposal. I already did some tweaking in the project settings and added armv6. What else do I have to do?
I symbolicated the crashreport I got from apple as you can see below.
However, the problem remains the same. I can not figure out why my app does not run on an iPhone 4. I found one piece of code that is mentioned as #6 of the last exceptions.
It is located in ViewController.m. This is my code at the specified line:
self.player =[[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
Last Exception Backtrace:
0 CoreFoundation 0x3742088f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x35125259 objc_exception_throw + 33
2 CoreFoundation 0x37420789 +[NSException raise:format:] + 1
3 CoreFoundation 0x374207ab +[NSException raise:format:] + 35
4 Foundation 0x37c0805f -[NSURL(NSURL) initFileURLWithPath:] + 79
5 Foundation 0x37c07ffb +[NSURL(NSURL) fileURLWithPath:] + 43
6 Podman 0x00021feb -[ViewController viewDidLoad] (ViewController.m:43)
7 UIKit 0x3112dc8b -[UIViewController view] + 167
8 UIKit 0x3112c461 -[UIWindow addRootViewControllerViewIfPossible] + 45
9 UIKit 0x3111ee87 -[UIWindow _setHidden:forced:] + 295
10 UIKit 0x3118f7d5 -[UIWindow makeKeyAndVisible] + 25
11 UIKit 0x3112ce6d -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1633
12 UIKit 0x311267dd -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 409
13 UIKit 0x310f4ac3 -[UIApplication handleEvent:withNewEvent:] + 1011
14 UIKit 0x310f4567 -[UIApplication sendEvent:] + 55
15 UIKit 0x310f3f3b _UIApplicationHandleEvent + 5827
16 GraphicsServices 0x33b3622b PurpleEventCallback + 883
17 CoreFoundation 0x373f4523 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 39
18 CoreFoundation 0x373f44c5 __CFRunLoopDoSource1 + 141
19 CoreFoundation 0x373f3313 __CFRunLoopRun + 1371
20 CoreFoundation 0x373764a5 CFRunLoopRunSpecific + 301
21 CoreFoundation 0x3737636d CFRunLoopRunInMode + 105
22 UIKit 0x3112586b -[UIApplication _run] + 551
23 UIKit 0x31122cd5 UIApplicationMain + 1081
24 Podman 0x00021e7b main (main.m:16)
25 Podman 0x00021e30 start + 40
I get the below error when I test my application on my iPhone, yet the error doesnt occur in the Simulator. Its when I load up my rootViewController which is a UITableView. I am relatively new to iOS programming, and I was just wondering if anybody could shed any light on it!
Regards,
Michael.
Use this code to go to my RootView.
- (IBAction)goToRootView {
RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:rootViewController animated:YES];
[rootViewController release];
}
2011-09-12 14:39:55.951 LeagueProject[773:707] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:
(
0 CoreFoundation 0x3684b64f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x33aa4c5d objc_exception_throw + 24
2 CoreFoundation 0x367b6069 -[__NSArrayM objectAtIndex:] + 184
3 LeagueProject 0x0000302f -[RootViewController tableView:numberOfRowsInSection:] + 58
4 UIKit 0x356827c7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1338
5 UIKit 0x356836bb -[UITableViewRowData rectForFooterInSection:] + 66
6 UIKit 0x356835f5 -[UITableViewRowData heightForTable] + 40
7 UIKit 0x35683453 -[UITableView(_UITableViewPrivate) _updateContentSize] + 206
8 UIKit 0x3567ebc9 -[UITableView _rectChangedWithNewSize:oldSize:] + 384
9 UIKit 0x3567d833 -[UITableView setFrame:] + 158
10 UIKit 0x35684e0f -[UIView(Geometry) resizeWithOldSuperviewSize:] + 274
11 UIKit 0x356510bd -[UIView(Geometry) resizeSubviewsWithOldSize:] + 120
12 UIKit 0x356364e9 -[UIView(Geometry) setFrame:] + 336
13 UIKit 0x35688193 -[UIViewControllerWrapperView setFrame:] + 62
14 UIKit 0x35676079 -[UINavigationController _startTransition:fromViewController:toViewController:] + 960
15 UIKit 0x35675c43 -[UINavigationController _startDeferredTransitionIfNeeded] + 182
16 UIKit 0x35667d5d -[UINavigationController pushViewController:transition:forceImmediate:] + 640
17 UIKit 0x35667ad3 -[UINavigationController pushViewController:animated:] + 34
18 LeagueProject 0x0000917d -[splashView goToRootView] + 116
19 CoreFoundation 0x367bb571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
20 UIKit 0x3564dec9 -[UIApplication sendAction:to:from:forEvent:] + 84
21 UIKit 0x3564de69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
22 UIKit 0x3564de3b -[UIControl sendAction:to:forEvent:] + 38
23 UIKit 0x3564db8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
24 UIKit 0x3564e423 -[UIControl touchesEnded:withEvent:] + 342
25 UIKit 0x3564cbf5 -[UIWindow _sendTouchesForEvent:] + 368
26 UIKit 0x3564c56f -[UIWindow sendEvent:] + 262
27 UIKit 0x35635313 -[UIApplication sendEvent:] + 298
28 UIKit 0x35634c53 _UIApplicationHandleEvent + 5090
29 GraphicsServices 0x35f6fe77 PurpleEventCallback + 666
30 CoreFoundation 0x36822a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
31 CoreFoundation 0x3682483f __CFRunLoopDoSource1 + 166
32 CoreFoundation 0x3682560d __CFRunLoopRun + 520
33 CoreFoundation 0x367b5ec3 CFRunLoopRunSpecific + 230
34 CoreFoundation 0x367b5dcb CFRunLoopRunInMode + 58
35 GraphicsServices 0x35f6f41f GSEventRunModal + 114
36 GraphicsServices 0x35f6f4cb GSEventRun + 62
37 UIKit 0x3565fd69 -[UIApplication _run] + 404
38 UIKit 0x3565d807 UIApplicationMain + 670
39 LeagueProject 0x000025a7 main + 82
40 LeagueProject 0x00002550 start + 40
)
terminate called after throwing an instance of 'NSException'
Your error is an index 0 beyond bounds for empty array error. Put breakpoints on the lines where you access arrays. When you find out which array is causing the problem, either the solution will be trivial, or you can add a bit more to your question and ask for further help.
It looks like the problem is in your implementation of [RootViewController tableView:numberOfRowsInSection:]. You are trying to access a member of a NSMutableArray that is empty - hence the error 'index 0 beyond bounds for empty array'.
I have a problem that occurs from time to time and I can't find
the solution, can someone help me? Thanks
Here is the log of the crash and where the method is called
0 libobjc.A.dylib 0x00003fb0 objc_msgSend + 16
1 Authentic 0x00048ce2 -[JobsSubtitleView touchUp:] (JobsSubtitleView.m:172)
2 CoreFoundation 0x00026486 -[NSObject performSelector:withObject:withObject:] + 46
3 UIKit 0x00032bf8 -[UIApplication sendAction:to:from:forEvent:] + 56
4 UIKit 0x00032bb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 24
5 UIKit 0x00032b92 -[UIControl sendAction:to:forEvent:] + 38
6 UIKit 0x00032902 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 486
7 UIKit 0x0003307a -[UIControl touchesEnded:withEvent:] + 470
8 UIKit 0x00031914 -[UIWindow _sendTouchesForEvent:] + 312
9 UIKit 0x0003133a -[UIWindow sendEvent:] + 374
10 UIKit 0x000076e6 -[UIApplication sendEvent:] + 350
11 UIKit 0x000070d2 _UIApplicationHandleEvent + 5802
12 GraphicsServices 0x00004f44 PurpleEventCallback + 876
13 CoreFoundation 0x00083a28 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
14 CoreFoundation 0x000839ca __CFRunLoopDoSource1 + 134
15 CoreFoundation 0x000825f0 __CFRunLoopRun + 1364
16 CoreFoundation 0x00023f72 CFRunLoopRunSpecific + 294
17 CoreFoundation 0x00023e3a CFRunLoopRunInMode + 98
18 GraphicsServices 0x0000411e GSEventRunModal + 150
19 UIKit 0x00002472 UIApplicationMain + 1074
20 Authentic 0x0006bbd0 main (main.m:17)
21 Authentic 0x00002e8c start + 32
- (void) touchUp:(id)sender {
if(![[UIApplication sharedApplication] isNetworkActivityIndicatorVisible]) {
UIButton *jobsSubtitleButton = (UIButton*)sender;
[jobsSubtitleButton setSelected:!jobsSubtitleButton.selected];
[jobsViewController setClickType:YES]; /*** LINE 172 ***/
if(![jobsViewController isSearching]) {
[jobsViewController setIsSearching:YES];
if([jobsViewController clickType]) {
[self performSelector:#selector(reloadJobs) withObject:nil afterDelay:1.0f];
} else {
[self performSelector:#selector(reloadJobs) withObject:nil];
}
}
}
}
You have not provided enough code to make the root cause of the problem clear. The crash happens because the jobsViewController ivar in your object points to an object that has already been deallocated. But why was it deallocated at this point? There is no way to know based on this code. The most likely cause is that you forgot to retain it or the property was not declared as "retain". But, there could be a number of programming mistakes that were the root cause. You will need to do a code review looking specifically for problems related to not retaining the object pointed to by jobsViewController.
I'm experience an occasional crash of my iPhone application where I'm getting the following exception
NSGenericException', reason: '*** Collection <CALayerArray: 0x26f6b0> was mutated while being enumerated.
With the stack trace on the crashing thread of
Thread 0 Crashed:
0 libSystem.B.dylib 0x00078ac8 __kill + 8
1 libSystem.B.dylib 0x00078ab8 kill + 4
2 libSystem.B.dylib 0x00078aaa raise + 10
3 libSystem.B.dylib 0x0008d03a abort + 50
4 libstdc++.6.dylib 0x00044a20 __gnu_cxx::__verbose_terminate_handler() + 376
5 libobjc.A.dylib 0x00005958 _objc_terminate + 104
6 libstdc++.6.dylib 0x00042df2 __cxxabiv1::__terminate(void (*)()) + 46
7 libstdc++.6.dylib 0x00042e46 std::terminate() + 10
8 libstdc++.6.dylib 0x00042f16 __cxa_throw + 78
9 libobjc.A.dylib 0x00004838 objc_exception_throw + 64
10 CoreFoundation 0x0009f850 __NSFastEnumerationMutationHandler + 208
11 libobjc.A.dylib 0x0000a51a objc_enumerationMutation + 18
12 UIKit 0x00007bfe -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 142
13 UIKit 0x00007c2e -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 190
14 UIKit 0x00007cd2 -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:] + 22
15 UIKit 0x00007628 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 304
16 UIKit 0x000074e8 -[UIView(Hierarchy) addSubview:] + 16
17 UIKit 0x0006c350 +[UIViewControllerWrapperView wrapperViewForView:frame:] + 232
18 UIKit 0x00077d0c -[UINavigationController _startTransition:fromViewController:toViewController:] + 468
19 UIKit 0x00077abc -[UINavigationController _startDeferredTransitionIfNeeded] + 176
20 UIKit 0x00077a00 -[UINavigationController viewWillLayoutSubviews] + 8
21 UIKit 0x0006dca8 -[UILayoutContainerView layoutSubviews] + 132
22 UIKit 0x0000fbc0 -[UIView(CALayerDelegate) _layoutSublayersOfLayer:] + 20
23 CoreFoundation 0x0003e2e4 -[NSObject(NSObject) performSelector:withObject:] + 16
24 QuartzCore 0x0000f942 -[CALayer layoutSublayers] + 114
25 QuartzCore 0x0000f6fa CALayerLayoutIfNeeded + 178
26 QuartzCore 0x000094c4 CA::Context::commit_transaction(CA::Transaction*) + 204
27 QuartzCore 0x000092da CA::Transaction::commit() + 186
28 QuartzCore 0x0002d9b6 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 46
29 CoreFoundation 0x00030236 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 10
30 CoreFoundation 0x000300aa __CFRunLoopDoObservers + 406
31 CoreFoundation 0x000276b4 __CFRunLoopRun + 848
32 CoreFoundation 0x00027270 CFRunLoopRunSpecific + 224
33 CoreFoundation 0x00027178 CFRunLoopRunInMode + 52
34 GraphicsServices 0x000045ec GSEventRunModal + 108
35 GraphicsServices 0x00004698 GSEventRun + 56
36 UIKit 0x0000411c -[UIApplication _run] + 396
37 UIKit 0x00002128 UIApplicationMain + 664
38 iDriveGreen 0x00003026 main (main.m:13)
39 iDriveGreen 0x00002ff0 start + 32
This crash is being triggered after the following code is executed.
StopRouteViewController *stopVC = [[StopRouteViewController alloc] init];
[UIView transitionWithView:self.navigationController.view
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[self.navigationController pushViewController:stopVC animated:NO];
}
completion:NULL];
[stopVC release];
Does this look blatantly wrong to anyone? My current thought is that is is either tied to stopVC being released before it is pushed or with transitioning with navigationController.view while at the same time pushing a new viewController to the navigationController.
Since this only occurs occasionally, I'd like to have a little more confidence before I commit a potential fix.
Yes, this is incorrect usage of the API. -[UINavigationController pushViewController:animated:] handles animation on its own. Even if you pass NO as the second argument, it is still manipulating the view hierarchy, which is what's causing your crash.
Basically, there is no reason to put a call to -[UINavigationController pushViewController:animated:] in an animation block, as you have done. If you want to animate the push of your controller, pass YES as the second argument.
I have a problem with my iPhone app, I have a crash log from a tester that i ran through symbolicatecrash but I'm still not sure what could be causing it. The crash only happens on one tester's device and I am unable to reproduce it on my device.
Hardware Model: iPhone2,1
OS Version: iPhone OS 4.0.1 (8A306)
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x534f5031
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x0000286c objc_msgSend + 16
1 UIKit 0x000765c6 -[UINavigationItem _updateViewsForBarSizeChangeIfNecessary] + 30
2 UIKit 0x000a26c8 -[UINavigationBar _popNavigationItemWithTransition:] + 212
3 UIKit 0x000a25d0 -[UINavigationBar popNavigationItemAnimated:] + 76
4 UIKit 0x000a2492 -[UINavigationBar _handleMouseUpAtPoint:] + 390
5 UIKit 0x000a22f2 -[UINavigationBar touchesEnded:withEvent:] + 54
6 UIKit 0x000614e6 -[UIWindow _sendTouchesForEvent:] + 362
7 UIKit 0x00060e60 -[UIWindow sendEvent:] + 256
8 UIKit 0x0005cb54 -[UIApplication sendEvent:] + 292
9 UIKit 0x0005c500 _UIApplicationHandleEvent + 5016
10 GraphicsServices 0x00004140 PurpleEventCallback + 660
11 CoreFoundation 0x00071aa4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 20
12 CoreFoundation 0x00073848 __CFRunLoopDoSource1 + 160
13 CoreFoundation 0x00074626 __CFRunLoopRun + 514
14 CoreFoundation 0x0001d8e4 CFRunLoopRunSpecific + 224
15 CoreFoundation 0x0001d7ec CFRunLoopRunInMode + 52
16 GraphicsServices 0x000036e8 GSEventRunModal + 108
17 GraphicsServices 0x00003794 GSEventRun + 56
18 UIKit 0x000062a0 -[UIApplication _run] + 396
19 UIKit 0x00004e10 UIApplicationMain + 664
20 app 0x0000240c main (main.m:14)
21 app 0x000023a8 start + 44
The crash happens from taking a photo, going to new view, manipulating photo, saving it, sending it, returning to the previous view and then trying to go back to the view before that.
Make sure you're properly retaining and releasing your nib objects as outlined here.