CCLabelBMFont not ignoring missing -hd version unless setString is called after creation.

This one took me some time to figure out since I thought I was just doing something wrong.

I have Retina enabled, however I am using only one texture set. I do not have any hd extensions, but all of our textures are higher res. This gives me the ability to use the same textures on all devices, and still keep it looking pretty on high res devices since cocos2d will just load what it sees as the low res version when it cannot find ahd extension. For the most part this has worked great, except when I started to try and use text the other day. When creating a label with CCLabelBMFont::labelWithString I get text that is made up of the wrong image data. After doing some digging, it appears that the data is being built from what it thinks is the -hd version of the texture, thus instead of building from a rect of size 1x1 its building it 2x2 and displaying 4 characters in a square per character block. However if I call setString with the same data I used in the original label creation the problem goes away. So I assume there is a bug in labelWithString, but the workaround is simple enough. Just FYI. Thanks!

Thanks, bug #668 created.

Could you explain what you do step by step? Attaching a picture is better.

I find the reason, it is in line 493 of CCLabelBMFont.cpp

fontChar->initWithBatchNode(this, rect);

It should use

fontChar->initWithBatchNodeRectInPixels(this, rect);

However if I call setString with the same data I used in the original label creation the problem goes away
The reason is:
CCLabelBMFont::labelWithString() > setString> createFontChars(). But when you call setString() the next time, createFontChars() will do this branch

else // line 497
            {
                // reusing fonts
                fontChar->setTextureRectInPixels(rect, false, rect.size);

                // restore to default in case they were modified
                fontChar->setIsVisible(true);
                fontChar->setOpacity(255);
            }

As you see, it invoke setTextureRectInPixels(), which will compute correct rect size.