In Cocos2D using blocks to create a menu action causes a SIGABRT error in that scene’s init method:
CCLabelTTF *label = [CCLabelTTF labelWithString:@"test" fontName:@"Times" fontSize:12];
CCMenuItemLabel *toCauseCrash = [CCMenuItemLabel itemWithLabel:label block:^(id sender) {
NSLog(@"Blocks work?");
}];
Tried the newest Cocos2D, nothing. This forum post promises (a) a hotfix soon, and an edit to the “BuildSettings-iOS.xcconfig” file (which doesn’t exist, as far as I can tell).
(1) Does anyone know how to fix Cocos2D to allow blocks in menus?
(2) Does anyone know what xcconfig file the above post is talking about, or how to find it? (That’s a Kobold2d thing)
Edit: here are the code examples I’ve tried after setting “-force_load $(BUILT_PRODUCTS_DIR)/” in OTHER_LINKER_FLAGS:
id blockAction = [CCCallBlock actionWithBlock:^{
NSLog(@"Blocks action");
}];
void (^reusableBlock)(id sender) = ^(id sender) {
NSLog(@"Reusable block");
};
// SIGABRT:
CCMenuItemLabel *menuItem = [CCMenuItemLabel itemWithLabel:myLabel block:blockAction];
// SIGABRT:
CCMenuItemLabel *menuItem = [CCMenuItemLabel itemWithLabel:myLabel block:reusableBlock];
Seems like for right now the answer is: Blocks are problematic, even when you use -force_load on the cocos2d lib. I will be super happy for the day there is a different answer I can accept on this question.