Bug in CCLabelBMFont : invisible chars

Bug in CCLabelBMFont : invisible chars
0.0 0


Hi all,
I had a bug today about a character never showing up using CCLabelBMFont. After some debugging, I found the problem and fixed it locally (I don’t know if it’s the best fix or if there are similar errors elsewhere).
in CCLabelBMFont::createFontChars(), when the characters are initialized there is the following code:

float yOffset = (float) (m_pConfiguration~~>m_uCommonHeight~~ fontDef.yOffset);

As m_uCommonHeight is unsigned, if yOffset is greater than m_uCommonHeight, it given a huge number instead of a negative one. The y position of the character is huge, and of course out of screen.

I fixed it my casting the unsigned int into int.

float yOffset = (float) ((int)m_pConfiguration~~>m_uCommonHeight~~ fontDef.yOffset);

Hoping this helps someone!


OK, seems you’re right. The same bug exists in cocos2d-iphone.
Fixed in https://github.com/cocos2d/cocos2d-x/commit/0a4f466b5bca1269d19a73c298520497ed571f94#commitcomment-705485
I only modified this line

// float yOffset = (float) (m_pConfiguration->m_uCommonHeight - fontDef.yOffset);
float yOffset = (float)(m_pConfiguration->m_uCommonHeight) - fontDef.yOffset;