I’m writing a AVG game for iPad. The conversation layer performs an animation that show characters one by one.
I use CCLayer::schedule(selector, interval) to implement this animation, and the selector is something like this:
utf8_substr((utf8*)dialog, 0, dialogSubCharNum, (utf8*)dialogSub);
The program will crash randomly (but in a large possibility) at the “setString” line. Looking into cocos2d-x lib, I find it crashes at CCImage_ios.mm:443:
// normal fonts
if( [font isKindOfClass:[UIFont class] ] )
[str drawInRect:CGRectMake(0, 0, dim.width, dim.height) withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:align]; //<— program received signal “EXC_BAD_ACCESS”
The content of str in gdb is correct.
I set the schedule interval as 0.075f. Since the number of characters are not so large, the performance is no problem (60fps) when it does not crash.
Is there sth. wrong with using scheduler? Or perhaps it is a bug in cocos2d-x? Any idea? Thanks