How do I draw NSAttributedString in iOS5? - ios5

When I try to draw an NSAttributedString and run it in iOS5 simulator I get a crash. In iOS6 it runs fine. I don't understand what I am doing wrong, because from what I read my code should also work on iOS5. My setup:
xCode 4.6.2
iOS 6.1 SDK
iOS 5.1 deployment target
I run the following code:
- (void)drawRect:(CGRect)rect
{
NSDictionary *txtAttr = #{
(NSString *)kCTFontAttributeName : [UIFont boldSystemFontOfSize:16]
};
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:#"foobar" attributes:txtAttr];
CGContextRef ctx = UIGraphicsGetCurrentContext();
// flip context
CGContextSaveGState(ctx);
CGContextTranslateCTM(ctx, 0, self.bounds.size.height);
CGContextScaleCTM(ctx, 1, -1);
// I get a crash on the line below
CTLineRef line = CTLineCreateWithAttributedString(
(__bridge CFAttributedStringRef)string
);
CGContextSetTextPosition(ctx, 0, 4);
CTLineDraw(line, ctx);
CFRelease(line);
CGContextRestoreGState(ctx);
}
This crashes on CTLineCreateWithAttributedString with the stack trace:
#0 0x00140c68 in TAttributes::TAttributes(__CFDictionary const*) ()
#1 0x0011c499 in TTypesetterAttrString::Initialize(__CFAttributedString const*) ()
#2 0x0011c313 in TTypesetterAttrString::TTypesetterAttrString(__CFAttributedString const*) ()
#3 0x0010db14 in CTLineCreateWithAttributedString ()
#4 0x00065e5f in -[AttributedLabel drawRect:] at AttributedLabel.m:77
#5 0x003c8bd3 in -[UIView(CALayerDelegate) drawLayer:inContext:] ()
#6 0x002a7963 in -[CALayer drawInContext:] ()
#7 0x002b9f80 in backing_callback(CGContext*, void*) ()
#8 0x001d83fd in CABackingStoreUpdate_ ()
#9 0x002b9e2e in CA::Layer::display_() ()
#10 0x002a7a3d in -[CALayer _display] ()
#11 0x002adfd5 in CA::Layer::display() ()
#12 0x002a7a63 in -[CALayer display] ()
#13 0x002b19ae in CA::Layer::display_if_needed(CA::Transaction*) ()
#14 0x00236509 in CA::Context::commit_transaction(CA::Transaction*) ()
#15 0x002383f6 in CA::Transaction::commit() ()
#16 0x00237ad0 in CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) ()
#17 0x0140c99e in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#18 0x013a3640 in __CFRunLoopDoObservers ()
#19 0x0136f4c6 in __CFRunLoopRun ()
#20 0x0136ed84 in CFRunLoopRunSpecific ()
#21 0x0136ec9b in CFRunLoopRunInMode ()
#22 0x018157d8 in GSEventRunModal ()
#23 0x0181588a in GSEventRun ()
#24 0x0038a626 in UIApplicationMain ()
The place where the crash happens is shown below:
0x140c5a: calll 0x11c812 ; TCFRetained<__CFDictionary const*>::Retain(__CFDictionary const*)
0x140c5f: movl 8(%ebp), %eax
0x140c62: movl 4(%eax), %eax
0x140c65: movl 20(%eax), %eax
0x140c68: movl 8(%eax), %eax ;I get a Thread 1: EXC_BAD_ACCESS (code=2, address=0x08) here
0x140c6b: testl %eax, %eax
0x140c6d: je 0x140d0c ; TAttributes::TAttributes(__CFDictionary const*) + 482

The mistake is to use UIFont. iOS5 expects a CTFont, which is a Core Foundation type. Below is the code I used to get it working:
CTFontRef font = CTFontCreateWithName((CFStringRef)#"HelveticaNeue-Bold", 16, NULL);
NSDictionary *txtAttr = #{
(NSString *)kCTFontAttributeName : (id)CFBridgingRelease(font)
};
Use your font book app to locate the font and use the PostScript name. I would not have figured out this if I had not read: NSAttributedString in CATextLayer causes EXC_BAD_ACCESS (ios 5.0)

I don't know if you want to draw text line by line but here is my code that I used to draw NSAttributedString on a custom UIView:
I changed the code according to your attributed string:
- (void)drawRect:(CGRect)rect {
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:#"yourString"];
UIFont *font = [UIFont boldSystemFontOfSize:16];
CTFontRef fontR = CTFontCreateWithName((CFStringRef)font.fontName, font.pointSize, NULL);
[attrString addAttribute:(NSString*)kCTFontAttributeName
value:(id)fontR
range:NSMakeRange(0, [yourText length])];
CFRelease(fontR);
CGMutablePathRef path = CGPathCreateMutable();
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrString);
// added 3 pixels at the top of the frame so that the text is not cuted
CGRect newRect = CGRectMake(rect.origin.x, rect.origin.y - 3, rect.size.width, rect.size.height);
CGPathAddRect(path, NULL, newRect);
CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL);
CFRelease(framesetter);
CGPathRelease(path);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CTFrameDraw(frameRef, context);
CFRelease(frameRef);
[super drawRect:newRect];
}
I hope I didn't forgot anything, because I also perform some calculations on the attributed text and I removed them for a better example.
Hope this helps ;)

Related

How do I know when safe to ignore __cxa_throw on an All Exceptions breakpoint?

I am on Xcode 4.5.1. I think this is relatively new behavior I am seeing.
I prefer to develop and test my projects with the "All Exceptions" breakpoint enabled.
I have been running into a scenario where I am loading thumbnail images to cells in a tableview, where I am getting a __cxa_throw exception. When I click the "Continue program execution" button, Xcode continues its merry way. I get the thumbnails. App seems to work fine. I am looking for some tips on how I can determine if this is something safe to ignore. Like maybe some pointers on understanding the stack trace? Or something else?
Here is the snippet of code:
NSString *imageStr = item.thumbURL;
imageStr = [imageStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *imageURL;
if (![imageStr isEqualToString:#""]) {
imageURL = [NSURL URLWithString:imageStr];
NSLog(#"imageURL: %#",imageURL);
if (imageURL == nil) {
NSLog(#"imageUrl was nil for string: %#",imageStr);
} else {
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
//spinner.frame = CGRectMake(cell.imageView.frame.size.width/2,cell.imageView.frame.origin.y + cell.imageView.frame.size.height/2,cell.imageView.frame.size.width,cell.imageView.frame.size.height);
spinner.frame = CGRectMake(10,20,40,40);
[spinner startAnimating];
[cell addSubview:spinner];
dispatch_queue_t downloadQueue = dispatch_queue_create("thumbnail downloader", NULL);
dispatch_async(downloadQueue, ^{
NSLog(#"Network request for tour_thumb image: %#",imageStr);
UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:imageURL]];
dispatch_async(dispatch_get_main_queue(), ^{
[spinner removeFromSuperview];
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(8, 8, cell.contentView.frame.size.width/2 - 16, cell.contentView.frame.size.height - 16)];
imgView.image = img;
[cell.contentView addSubview:imgView];
});
});
dispatch_release(downloadQueue);
}
}
Here is what I see on the stack trace:
#0 0x34a9c524 in __cxa_throw ()
#1 0x387014ce in AddChildNode(XMP_Node*, XML_Node const&, char const*, bool) ()
#2 0x38700d22 in RDF_LiteralPropertyElement(XMP_Node*, XML_Node const&, bool) ()
#3 0x3870094e in RDF_PropertyElementList(XMP_Node*, XML_Node const&, bool) ()
#4 0x38700608 in ProcessRDF(XMP_Node*, XML_Node const&, unsigned int) ()
#5 0x3871480a in XMPMeta::ParseFromBuffer(char const*, unsigned int, unsigned int) ()
#6 0x387095c0 in WXMPMeta_ParseFromBuffer_1 ()
#7 0x38725578 in TXMPMeta<std::string>::ParseFromBuffer(char const*, unsigned int, unsigned int) ()
#8 0x387254de in TXMPMeta<std::string>::TXMPMeta(char const*, unsigned int) ()
#9 0x38722b70 in CreateMetadataFromXMPDataInternal(char const*, unsigned long, unsigned int) ()
#10 0x38739a50 in readXMPProperties ()
#11 0x386a01fc in readXMPData ()
#12 0x3868cec8 in initImageJPEG ()
#13 0x3868c2ee in _CGImagePluginInitJPEG ()
#14 0x3867e274 in makeImagePlus ()
#15 0x3867ddde in CGImageSourceCreateImageAtIndex ()
#16 0x38e117b6 in _UIImageRefFromData ()
#17 0x38e116c6 in -[UIImage initWithData:] ()
#18 0x0004cb0a in __57-[ViewController tableView:cellForRowAtIndexPath:]_block_invoke_0 at ViewController.m:335
#19 0x313fc792 in _dispatch_call_block_and_release ()
#20 0x313ffb3a in _dispatch_queue_drain ()
#21 0x313fd67c in _dispatch_queue_invoke ()
#22 0x31400612 in _dispatch_root_queue_drain ()
#23 0x314007d8 in _dispatch_worker_thread2 ()
#24 0x394767f0 in _pthread_wqthread ()
#25 0x39476684 in start_wqthread ()
This is obviously deep within the implementation and C++ exceptions can be part of the normal flow, if they've decided to use exceptions to signal errors internally.
If you aren't writing any C++ yourself then it is safe to ignore.
Just trap the standard Objective-C exception:
objc_exception_throw
Go here:
And do this:
To turn this:
into this:
You'll still get a lot of the benefit of adding a breakpoint, but won't have your app crash for stuff you probably aren't responsible for anyway. Now if you are working with C++ then you darn better worry about it.

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))];
}

Scheduled timer crash after popScene

I seem to be getting a crash right after doing [[CCDirector sharedDirector] popScene]. I am not really sure why. Any clues would help, thanks!
Crashlog:
#0 0x99e5ef84 in objc_msgSend ()
#1 0x302d543a in __NSFastEnumerationMutationHandler ()
#2 0x00046b46 in -[CCScheduler tick:] (self=0x1919ac0, _cmd=0x7b682, dt=0.0333320014) at /Users/Sup3rpanda/Dev/My Projects/Puzzle/libs/cocos2d/CCScheduler.m:211
#3 0x0001fb52 in -[CCDirector mainLoop] (self=0xf10a30, _cmd=0x76272) at /Users/Sup3rpanda/Dev/My Projects/Puzzle/libs/cocos2d/CCDirector.m:208
#4 0x305355cd in __NSFireTimer ()
#5 0x302454a0 in CFRunLoopRunSpecific ()
#6 0x30244628 in CFRunLoopRunInMode ()
#7 0x32044c31 in GSEventRunModal ()
#8 0x32044cf6 in GSEventRun ()
#9 0x309021ee in UIApplicationMain ()
#10 0x00002e94 in main (argc=1, argv=0xbfffef60) at /Users/Sup3rpanda/Dev/My Projects/Puzzle/main.m:13
Scheduled timer:
tGridTimer = [[CCTimer alloc] initWithTarget: self selector: #selector(gridSlideUpForced2:) interval: sGridSpeed];
[[CCScheduler sharedScheduler] scheduleTimer:tGridTimer];
Bit of CoCos 2d code that appears to be related to crashing:
-(void) tick: (ccTime) dt
{
if( timeScale_ != 1.0f )
dt *= timeScale_;
for( id k in methodsToRemove )
[scheduledMethods removeObject:k];
[methodsToRemove removeAllObjects];
for( id k in methodsToAdd )
[scheduledMethods addObject:k];
[methodsToAdd removeAllObjects];
for( CCTimer *t in scheduledMethods )
impMethod(t, fireSelector, dt);
[[CCScheduler sharedScheduler] scheduleTimer:tGridTimer];
Are you cleaning up your timers in onExit or dealloc in your scene class? Could be the scene still thinks some of the schedulers are still running

EXC_BAD_ACCESS on mapView

i get this error and EXC_BAD_ACESS when i run my maps application... any idea
#0 0x3510741c in objc_msgSend ()
#1 0x30a69364 in -[CLLocationManager onClientEventLocation:] ()
#2 0x30a66960 in -[CLLocationManager onClientEvent:supportInfo:] ()
#3 0x30a66b28 in OnClientEvent ()
#4 0x30a5f860 in CLClientInvokeCallback ()
#5 0x30a633e4 in CLClientHandleDaemonData ()
#6 0x357a902c in __CFMessagePortPerform ()
#7 0x3577be46 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#8 0x3577be04 in __CFRunLoopDoSource1 ()
#9 0x3576e0a4 in __CFRunLoopRun ()
#10 0x3576dd7a in CFRunLoopRunSpecific ()
#11 0x3576dc88 in CFRunLoopRunInMode ()
#12 0x336ace8c in GSEventRunModal ()
#13 0x318f0f94 in -[UIApplication _run] ()
#14 0x318ee4d4 in UIApplicationMain ()
#15 0x0000281c in main (argc=1, argv=0x2ffff5e0) at /Users/abcd/Desktop/wataproject/main.m:14
http://brainwashinc.wordpress.com/2010/01/05/mapkit-crash-getting-user-location/
This helped me solve this issue
#vivianaranha's approach might solve the issue but I believe (after encountering this myself) that you are doing something else bad.
Specifically, in my case I had set mapView.showsUserLocation = YES so under the hood mapView was wiring itself up to the CLLocationManager. The solution was to ensure that I called mapView.showsUserLocation = NO in viewWillDisappear.
Also I discovered that you must have mapView.userTrackingMode set to what you require before you make the call to mapView.showsUserLocation = YES. Putting it all together you end up with something like this:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.mapView.userTrackingMode = MKUserTrackingModeFollow;
self.mapView.showsUserLocation = YES;
self.mapView.delegate = self;
}
- (void)viewWillDisappear:(BOOL)animated {
self.mapView.userTrackingMode = MKUserTrackingModeNone;
self.mapView.showsUserLocation = NO;
self.mapView.delegate = nil;
[super viewWillDisappear:animated];
}

CALayer position contains NaN: [nan -0.5]

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!