0
votes

I am converting my project from using Cocos2D v2.1 to V3.0. It's a UIKit project with Cocos2D added as a sub-project and the director loaded lazily in a couple of viewcontrollers.

I managed to get rid of all the compiler warnings, it runs fine and seems to load the director fine, but then crashes as follows:

-[NSConcreteMutableAttributedString hasAttribute:]: unrecognized selector sent to instance 0xc4f8ff0
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableAttributedString hasAttribute:]: unrecognized selector sent to instance 0xc4f8ff0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0291a1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x026998e5 objc_exception_throw + 44
    2   CoreFoundation                      0x029b7243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0290a50b ___forwarding___ + 1019
    4   CoreFoundation                      0x0290a0ee _CF_forwarding_prep_0 + 14
    5                       0x0019d7d0 -[CCLabelTTF updateTexture] + 544
    6                        0x0019d546 -[CCLabelTTF visit] + 70
    7                       0x00181c86 -[CCNode visit] + 566
    8                        0x00181c86 -[CCNode visit] + 566
    9                       0x00202b9d -[CCDirectorIOS drawScene] + 381
    10                       0x00203fdc -[CCDirectorDisplayLink mainLoop:] + 92

The breakpoint stops in the CCLabelTTF function - (BOOL) updateTexture at

#ifdef __CC_PLATFORM_IOS

    // Font color
    if (![formattedAttributedString hasAttribute:NSForegroundColorAttributeName])

There is only one CCLabelTTF in the code, and I create it like so:

self.scoreLabel = [CCLabelTTF labelWithString:NSLocalizedString(@"Score", @"") fontName:@"Marker Felt" fontSize:20 dimensions:CGSizeMake(100, 50)];
self.scoreLabel.horizontalAlignment = (CCTextAlignment)NSTextAlignmentRight;
scoreLabel.position = ccp(250,70);
[self addChild:scoreLabel z:1];

Any help much appreciated. I've searched Cocos2D forums and here and can't find anything similar to this issue.

1

1 Answers

0
votes

Ahh... just solved it. Since Cocos2d is a sub-project, I had to include the -ObjC flag under Other Linker Flags for the target. This wasn't necessary with v2.1, but then that version didn't use the NSAttributedString+CCAdditions category.