Search code examples
iphonecocos2d-iphoneretina-display

CCLabelBMFont (font size 600) crashes retina device (not simulator)


I'm using a CCLabelBMFont to display a very large letter in my game. The SD font size size is 300, HD font size is 600

letter =[CCLabelBMFont labelWithString:@"A" fntFile:@"font-test4.fnt"];

with the 4 supporting files (font-test4.fnt / -hd.fnt and font-test4.png / -hd.png

Everything works fine in both simulator modes (retina and non-retina).

However when running on an iPhone4 the CCLabelBMFont class asserts when sanity checking

// scaleW. sanity check

propertyValue = [nse nextObject];
NSAssert( [propertyValue intValue] <= [[CCConfiguration sharedConfiguration] maxTextureSize], @"CCLabelBMFont: page can't be larger than supported");

// scaleH. sanity check

propertyValue = [nse nextObject];
NSAssert( [propertyValue intValue] <= [[CCConfiguration sharedConfiguration] maxTextureSize], @"CCLabelBMFont: page can't be larger than supported");

I have no idea why this is happening.


Solution

  • You're hitting the maximum texture size limit. Check the png files of your bitmap font, specifically the HD variant. If it is larger than 2048 pixels in either dimension (width or height) then only the iPad 2 (with iOS 5.1), iPad 3 and iPhone 4S can load that texture. These devices support a maximum of 4096x4096 textures, the older devices only 2048x2048.

    Besides that, a font with font size 300/600 is just ridiculously large. You should think of alternative ways of doing what you're trying to achieve, because such a large font size is a huge waste of (still precious) memory.

    The Simulator doesn't care much about these issues though. It's running on your Mac, can use all your Mac's memory and other resources.