CALayer position contains NaN: [nan -0.5] - iphone

I see this log in the console when I run my app:
CALayer position contains NaN: [nan -0.5]
The app consists of a UITaBar of which the first tab is a UINavigationController. In the NavController I'm launching the AddressBookPicker. In the AddressBookPicker I'm only choosing to show phone numbers.
When I choose on a contact that has only email addresses, that is when I see this log.
I do not see any crashes or any issues for that matter, just the log printed onto the console. Want to make sure that this is not a hidden issue that crashes on me after the launch.
Below is a snippet of relevant code and the stacktrace. Not sure which other parts of the code to paste here, please let me know if there are any I can post that might help.
Any help/inputs appreciated.
Thanks!
Code
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
NSArray *displayedItems = [NSArray arrayWithObjects: [NSNumber numberWithInt:kABPersonPhoneProperty]), nil];
picker.displayedProperties = displayedItems;
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
Stacktrace
#0 0x00096377 in NSLog
#1 0x046b38c9 in CALayerSetPosition
#2 0x046b3846 in -[CALayer setPosition:]
#3 0x046b375f in -[CALayer setFrame:]
#4 0x002f510b in -[UIView(Geometry) setFrame:]
#5 0x003dbe6d in -[UILabel setFrame:]
#6 0x023ed095 in -[ABPersonTableViewDataSource reloadNoValueLabelAnimated:]
#7 0x0244cf53 in -[ABPersonTableViewDataSource reloadDataIncludingHeaderView:invalidatePropertyData:]
#8 0x023f30d4 in -[ABPersonTableViewDataSource reloadDataIncludingHeaderView:]
#9 0x023eabc9 in -[ABPersonViewControllerHelper prepareViewWithDisplayedProperties:person:allowActions:]
#10 0x023ea6bc in -[ABPersonViewControllerHelper loadViewWithDisplayedProperties:person:allowDeletion:allowActions:]
#11 0x023ea598 in -[ABPersonViewController loadView]
#12 0x0036a54f in -[UIViewController view]
#13 0x003689f4 in -[UIViewController contentScrollView]
#14 0x003787e2 in -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:]
#15 0x00376ea3 in -[UINavigationController _layoutViewController:]
#16 0x0037812d in -[UINavigationController _startTransition:fromViewController:toViewController:]
#17 0x00372ccd in -[UINavigationController _startDeferredTransitionIfNeeded]
#18 0x00379d8b in -[UINavigationController pushViewController:transition:forceImmediate:]
#19 0x00372b67 in -[UINavigationController pushViewController:animated:]
#20 0x02403bc2 in -[ABPeoplePickerNavigationController pushViewController:animated:]
#21 0x0242a424 in -[ABPeoplePickerNavigationController showCardForPerson:withMemberCell:animate:forceDisableEditing:personViewController:]
#22 0x0242ce20 in -[ABMembersViewController showCardForPerson:withMemberCell:animate:]
#23 0x0240a0ef in -[ABMembersController abDataSource:selectedPerson:atIndexPath:withMemberCell:animate:]
#24 0x023fdb47 in -[ABMembersDataSource tableView:didSelectRowAtIndexPath:]
#25 0x00333a48 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
#26 0x0032a32e in -[UITableView _userSelectRowAtIndexPath:]
#27 0x0003f21a in __NSFireDelayedPerform
#28 0x02631f73 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
#29 0x026335b4 in __CFRunLoopDoTimer
#30 0x0258fdd9 in __CFRunLoopRun
#31 0x0258f350 in CFRunLoopRunSpecific
#32 0x0258f271 in CFRunLoopRunInMode
#33 0x02f2f00c in GSEventRunModal
#34 0x02f2f0d1 in GSEventRun
#35 0x002ceaf2 in UIApplicationMain
#36 0x00002554 in main at main.m:14

This seems to now cause crashes in iOS 4.2. Try picking a contact with no phone number, you should go to a view that says No Phone numbers. The crash occurs when you go back to All Contacts then pick that contact again.
Is anyone else experiencing this problem?
edit: In my case, I am only displaying email addresses. Picking a contact without an email address twice causes the crash.

I'm having the same problem, though it doesn't appear to happen in the built in apps (eg. mail).
One slightly hackish workaround is to add the First and Last names to the list of displayed properties - it doesn't show the "no email address" layer in that case, but also doesn't crash.

I had the same problem with "CALayer position contains NaN:". The app was fine in iOS3.x and iOS4.1 devices, but crashed in iOS4.2.
In my case, I has the following code:
CGRect frame;
frame.size.height = kTableCellHeight - 11;
frame.size.width = widthCell - 30;
UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:frame];
The UILabel creation failed and shown that error. In my case, it was solved adding arbitrary values for frame.origin (for this UILabel purpose, it didn't matter)
CGRect frame;
frame.size.height = kTableCellHeight - 11;
frame.size.width = widthCell - 30;
frame.origin.x = 0;
frame.origin.y = 0;
UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:frame];
Maybe the problem with "CALayer position contains NaN" is because some nil, incomplete or undefined value or structure is being used.

I don't know.
I see this too - I am doing something completely different from you - I am using the route-me mapping engine to display scrollable maps.
I believe it has something to do with scrolling views - and a layer somehow involved in the scrolling. As some of the views you mentioned I believe are scrolling - this would concur with my observations.
I wish I had more data for you, but one thing I can tell you is that I have been working on the app for months, and have been testing it on the iPhone and iPad, devices and simulator, under OSes 3.2 and 4.0 - and have had no crashes or memory leaks [at all, or associated with this].
So in short - no idea - but I think you're okay!

Related

Getting EXC_BAD_ACCESS and app crash

I have a table view and and tapping on any cell there is a detail view, my app get crashed when returning from detail to table list view, after going in detail view more than once.
#0 0x32d98f1c in objc_msgSend ()
#1 0x358da150 in _UIView ()
#2 0x358da040 in -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] ()
#3 0x358da080 in -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] ()
#4 0x358da080 in -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] ()
#5 0x358d9f38 in -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:] ()
#6 0x358f81dc in -[UIView(Hierarchy) removeFromSuperview] ()
#7 0x359af870 in -[UIScrollView removeFromSuperview] ()
#8 0x35900180 in -[UIView dealloc] ()
#9 0x374ffd7a in -[NSObject(NSObject) release] ()
#10 0x358f8230 in -[UIView(Hierarchy) removeFromSuperview] ()
#11 0x35900180 in -[UIView dealloc] ()
#12 0x359afffc in -[UIScrollView dealloc] ()
#13 0x374ffd7a in -[NSObject(NSObject) release] ()
#14 0x3516f7f4 in __delayedPerformCleanup ()
#15 0x3754d526 in CFRunLoopTimerInvalidate ()
#16 0x375522ac in __CFRunLoopDoTimer ()
#17 0x37521a90 in __CFRunLoopRun ()
#18 0x3752150a in CFRunLoopRunSpecific ()
#19 0x37521418 in CFRunLoopRunInMode ()
#20 0x33e76d24 in GSEventRunModal ()
#21 0x3591d57c in -[UIApplication _run] ()
#22 0x3591a558 in UIApplicationMain ()
How can i track the main reason behind this crash.
Thanks for any help.
I think in detailView dealloc method you are releasing an object which
is already release. it may be one of the reason to crash the app
Could it possible, that you reuse the DetailViewController Variable and only change the Data ?
Because i think that's a retain/release problem.
I suggest you rerun with zombies enabled. That should help you to pin point the problem which is most likely to be a pointer to a released object.

UIScrollView won't scroll even when I set content size

I have a UIView that is a subview of UIScrollView.
I've done this to set the content size in viewDidLoad (useful snippet I found on this site):
CGFloat scrollViewHeight = 0.0f;
for (UIView* view in self.scrollView.subviews)
{
scrollViewHeight += view.frame.size.height;
}
[self.scrollView setContentSize:(CGSizeMake(320, scrollViewHeight))];
Using NSLogs I've determined the content size height is greater than the height of the scroll view. But, it still won't scroll. (I'm only interested in vertical scrolling.)
Scrolling is enabled in IB, so what am I missing?
This also happened to me - seems like when view is loaded from nib file some resizing happens after viewDidLoad and even after viewWillAppear.
The call stack shows it is resizeWithOldSuperviewSize who is doing that
#0 0x0000f040 in -[ScrollView setContentSize:] at .../ScrollView.m:49
#1 0x00092863 in -[UIScrollView _resizeWithOldSuperviewSize:] ()
#2 0x0007357a in -[UIView(Geometry) resizeWithOldSuperviewSize:] ()
#3 0x00072178 in __46-[UIView(Geometry) resizeSubviewsWithOldSize:]_block_invoke_0 ()
#4 0x01ccb5a7 in __NSArrayChunkIterate ()
#5 0x01ca303f in __NSArrayEnumerate ()
#6 0x01ca2a16 in -[NSArray enumerateObjectsWithOptions:usingBlock:] ()
#7 0x0007210f in -[UIView(Geometry) resizeSubviewsWithOldSize:] ()
#8 0x0056d14c in -[UIView(AdditionalLayoutSupport) _is_layout] ()
#9 0x00076dfe in -[UIView(Hierarchy) layoutSubviews] ()
#10 0x0007e92d in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] ()
#11 0x010fa6b0 in -[NSObject performSelector:withObject:] ()
#12 0x022a5fc0 in -[CALayer layoutSublayers] ()
#13 0x0229a33c in CA::Layer::layout_if_needed(CA::Transaction*) ()
#14 0x022a5eaf in -[CALayer layoutIfNeeded] ()
#15 0x0011d8cd in -[UIViewController window:setupWithInterfaceOrientation:] ()
#16 0x000661a6 in -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] ()
#17 0x00064cbf in -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] ()
#18 0x00064bd9 in -[UIWindow _setRotatableViewOrientation:duration:force:] ()
#19 0x00063e34 in __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke_0 ()
#20 0x00063c6e in -[UIWindow _updateToInterfaceOrientation:duration:force:] ()
#21 0x00064a29 in -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] ()
#22 0x00067922 in -[UIWindow setDelegate:] ()
#23 0x00111fec in -[UIViewController _tryBecomeRootViewControllerInWindow:] ()
#24 0x0005ebc4 in -[UIWindow addRootViewControllerViewIfPossible] ()
#25 0x0005edbf in -[UIWindow _setHidden:forced:] ()
#26 0x0005ef55 in -[UIWindow _orderFrontWithoutMakingKey] ()
#27 0x00067f67 in -[UIWindow makeKeyAndVisible] ()
#28 0x0000379a in -[AppDelegate application:didFinishLaunchingWithOptions:] at .../AppDelegate.m:24
I didn't find a proper solution yet except setting contentSize later by calling performSelector:withObject:afterDelay
-(void)viewDidLoad
{
[self performSelector:#selector(adjustScrollViewContentSize) withObject:nil afterDelay:0.1];
}
-(void)adjustScrollViewContentSize
{
_scrollView.contentSize = CGSizeMake(4000, 4000);
}
is userInteractionEnabled property equal to TRUE? Perhaps you have a subview over your scrollview that is stealing the touches?
I agree with Sepehr. Something else must be stealing your touches. You can test this buy adding UIScollViewDelegate to your class and add one of the event call back methods below. If when you touch your scroll view they dont get called then you know Sepehr is correct.
(void)scrollViewDidScroll:(UIScrollView *)scrollView
(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
The issue comes from auto layout setting the contentSize based on constraints. Since my view was complex and auto layout was not up to the task I solved it by overriding setContentView: and ignoring auto layouts zero height setContentSize: message.
#interface MyView : UIScrollView {}
#end
#implementation MyView
- (void)setContentSize:(CGSize)aSize {
if (aSize.height > 0)
[super setContentSize:aSize];
}
#end
As an alternative to the use of performSelector:withObject:afterDelay suggested by ddenis, you could call setContentSize in viewDidLayoutSubviews:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
//do stuff here to calculate the content width and height
// ...
//then set the content size accordingly
[self.scrollView setContentSize:(CGSizeMake(contentWidth, contentHeight))];
}

iOS: Crash when opening gamecenter achievements view

I'm coding a game for iphone in c++ and 100% opengl.
I need to add gamecenter to it so to show the UIViews I had to do something hackish.
void sb_socialShowAchievementsView(){
SocialDelegate* del = [[[SocialDelegate alloc] init] autorelease];
GKAchievementViewController *achievements = [[GKAchievementViewController alloc] init];
if (achievements != nil) {
achievements.achievementDelegate = del;
HelperViewController* hvc = [[[HelperViewController alloc] init] autorelease];
[globalGLView addSubview:hvc.view];
[hvc presentModalViewController: achievements animated: YES];
}
[achievements release];
}
SocialDelegate implements protocols GKAchievementViewControllerDelegate and GKLeaderboardViewControllerDelegate.
globalGLView is my EAGLView instance.
and HelperViewController is just a UIViewController subclass.
The problem is when I call sb_socialShowAchievementsView() the app receives a SIGABRT with the following call stack and message:
*** Assertion failure in -[UIButtonLabel setTextColor:], /SourceCache/UIKit_Sim/UIKit-1262.60.3/UILabel.m:312
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: color'
#0 0x98ece156 in __kill
#1 0x98ece148 in kill$UNIX2003
#2 0x98f60899 in raise
#3 0x98f769b8 in abort
#4 0x961a2fda in __gnu_cxx::__verbose_terminate_handler
#5 0x03022333 in _objc_terminate
#6 0x961a117a in __cxxabiv1::__terminate
#7 0x961a11ba in std::terminate
#8 0x961a12b8 in __cxa_throw
#9 0x03022481 in objc_exception_throw
#10 0x02e8b238 in +[NSException raise:format:arguments:]
#11 0x022c6e37 in -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
#12 0x0052260f in -[UILabel setTextColor:]
#13 0x005ec3d3 in -[UIButton layoutSubviews]
#14 0x002a0481 in -[CALayer layoutSublayers]
#15 0x002a01b1 in CALayerLayoutIfNeeded
#16 0x004bd976 in __-[UINavigationController _positionNavigationBarHidden:edge:]_block_invoke_1
#17 0x0043698f in +[UIView(Animation) _performWithoutAnimation:]
#18 0x004c1e26 in -[UINavigationController _positionNavigationBarHidden:edge:]
#19 0x004bd9ae in -[UINavigationController _positionNavigationBarHidden:]
#20 0x004bc0c3 in -[UINavigationController _updateBarsForCurrentInterfaceOrientation]
#21 0x004b99b1 in -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]
#22 0x004c0bfd in -[UINavigationController viewDidMoveToWindow:shouldAppearOrDisappear:]
#23 0x0044217f in -[UIView(Internal) _didMoveFromWindow:toWindow:]
#24 0x00440d94 in -[UIView(Hierarchy) _postMovedFromSuperview:]
#25 0x00439c30 in -[UIView(Internal) _addSubview:positioned:relativeTo:]
#26 0x00437f83 in -[UIView(Hierarchy) addSubview:]
#27 0x0049355b in -[UITransitionView transition:fromView:toView:]
#28 0x006a3a16 in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]
#29 0x004b710d in -[UIViewController presentModalViewController:withTransition:]
#30 0x0007ee96 in sb_socialShowAchievementsView at social-bindings-iphone.mm:184
I just can't get what am I doing wrong...
I encountered the exact same problem. I have a class that manages all the game center stuff which I wrote a couple of months ago, and it worked fine. I tried to import it to a new project, and called the standard methods to present the GKAchievementViewController, then it crashed with the same SIGABRT as you had. Then I tried authenticating the player first (which I would normally do before calling the achievements controller), and the problem went away. I guess it's a bug in the GameKit framework. I couldn't file a bug report because bug reporter obviously has it's own bugs :)

Navigation and MapKit makes app crash

I have an application which used top bar navigation and a MapView. On the map view I have placed some annotations and when selecting an annotation, pressing the disclosure button to go into a subview and then going back to the MapView using the back button my application crashes. It does not give me any errors.
Can anyone help me figure out why my application keeps crashing?
I have made a short video showing this mysterious crash (because I'm afraid that I do not explain it very well)
The video can be seen on this link http://snuzzer.dk/pub/iPhoneAppMapKitCrash.mov
Please tell me if you need to see any code in order to determine the reason for the crash. I am not sure what code would be necessary for this as I do not get any error.
EDIT: This is the output of my stack trace:
#0 0x01275a63 in objc_msgSend
#1 0x0586c860 in ??
#2 0x0037ef1d in -[UINavigationController setDisappearingViewController:]
#3 0x0037c4f6 in -[UINavigationController _clearLastOperation]
#4 0x0037ce3f in -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
#5 0x00509e23 in -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:]
#6 0x0050afd2 in -[UINavigationTransitionView _cleanupTransition]
#7 0x002f6665 in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
#8 0x002f64f7 in -[UIViewAnimationState animationDidStop:finished:]
#9 0x01ffa6cb in run_animation_callbacks
#10 0x01ffa589 in CA::timer_callback
#11 0x010f4fe3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
#12 0x010f6594 in __CFRunLoopDoTimer
#13 0x01052cc9 in __CFRunLoopRun
#14 0x01052240 in CFRunLoopRunSpecific
#15 0x01052161 in CFRunLoopRunInMode
#16 0x01a48268 in GSEventRunModal
#17 0x01a4832d in GSEventRun
#18 0x002d442e in UIApplicationMain
#19 0x00002918 in main at main.m:14
EDIT: It seems that when I do not release my annotationViewController the application does not crash. I will keep playing with the application to see if this is right. Can anyone tell me if this might be right and if so, why? And when would I release it then?
- (void)mapView:(MKMapView *)aMapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
for(MyAnnotation* a in mapView.annotations) { // searching for chosen annotation
if(view.annotation == a) {
// set array from plist
NSString *path = [[NSBundle mainBundle] pathForResource:#"Annotations" ofType:#"plist"];
NSMutableArray* anns = [[NSMutableArray alloc] initWithContentsOfFile:path];
AnnotationDetailViewController *annotationDetailViewController = [[AnnotationDetailViewController alloc] initWithNibName:#"AnnotationDetailViewController" bundle:nil];
annotationDetailViewController.ann = [anns objectAtIndex:[a.annId intValue]];
[self.navigationController pushViewController:annotationDetailViewController animated:YES];
[annotationDetailViewController release]; // this is the one that I think will correct the error
[anns release];
}
}
}
You should look for an ivar in AnnotationDetailViewController that you are under-retaining/over-releasing. I would suspect some UIView, perhaps an IBOutlet that you did not configure to retain, particularly if you also fail to set it to nil in viewDidUnload. I recommend you read Memory Management of Nib Objects if you haven't already.
It's difficult to debug this without the code, or more information about your variables, but that's where I would look given where it's crashing.

viewDidAppear called twice, but viewWillAppear called once

I have discovered that when my program starts, in one of my viewcontrollers the order of calling is viewDidAppear, viewWillAppear, viewDidAppear.
I was not expecting the first viewDidAppear to be called. What could be causing this and how do I fix it? ATM I have a flag in viewDiDAppear to check if viewWillAppear was called, but it's a hack.
The stacktrace (which is identical in bot calls to viewDidAppear)is:
#0 0x0000509e in -[MainView viewDidAppear:] at MainView.m:497
#1 0x3097e96e in -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
#2 0x30af3abe in -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:]
#3 0x30af4930 in -[UINavigationTransitionView _navigationTransitionDidStop]
#4 0x3091af0d in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
#5 0x3091ba9e in +[UIViewAnimationState popAnimationState]
#6 0x30af46fd in -[UINavigationTransitionView transition:fromView:toView:]
#7 0x30af3b01 in -[UINavigationTransitionView transition:toView:]
#8 0x30979f09 in -[UINavigationController _startDeferredTransitionIfNeeded]
#9 0x30a97d9c in -[UILayoutContainerView layoutSubviews]
#10 0x0040bd94 in -[CALayer layoutSublayers]
#11 0x0040bb55 in CALayerLayoutIfNeeded
#12 0x0040b3ae in CA::Context::commit_transaction
#13 0x0040b022 in CA::Transaction::commit
#14 0x308f942a in -[UIApplication _reportAppLaunchFinished]
#15 0x308fef33 in -[UIApplication handleEvent:withNewEvent:]
#16 0x308fad82 in -[UIApplication sendEvent:]
#17 0x309013e1 in _UIApplicationHandleEvent
#18 0x32046375 in PurpleEventCallback
#19 0x30245560 in CFRunLoopRunSpecific
#20 0x30244628 in CFRunLoopRunInMode
#21 0x308f930d in -[UIApplication _run]
#22 0x309021ee in UIApplicationMain
#23 0x00001e82 in main at main.m:14
I just ran into a very similar problem.
In my case, that was because of a bug from the ECSlidingViewController (https://github.com/edgecase/ECSlidingViewController).
I just updated the code from github, solved the problem.
Using a ECSlidingViewController, on top of the uikit navigationController, made the child's viewDidAppear called twice.
Put a break point in viewDidAppear, then inspect the call stack in the debugger. It will tell you what is calling the method.
When viewDidAppear is called, can you cancel another viewDidAppear in the event queue by following method ? Sometimes I use this to avoid some methods being called twice or more.
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(viewDidAppear) object:nil];
It's very likely that you want the behavior of viewDidLoad rather than viewDidAppear - viewDidAppear can be called multiple times by your ViewController when you're not expecting it to.