CCLabelBMFont - occasional crash on setString()

Hi All,

Has anybody had occasional crashes in CCLabelBMFont? It’s happening for me in Android. Here’s the stacktrace:

********** Crash dump: **********
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000003
Stack frame #00  pc 00010de8  /system/lib/libc.so (dlfree+1071)
Stack frame #01  pc 00011005  /system/lib/libc.so (dlrealloc+176)
Stack frame #02  pc 0000d9e7  /system/lib/libc.so (realloc+10)
Stack frame #03  pc 002c3cd0  /data/app-lib//libgame.so (cocos2d::CCTextureAtlas::resizeCapacity(unsigned int)+260): Routine cocos2d::CCTextureAtlas::resizeCapacity(unsigned int) at /Users/.../Projects/cocos2d-x/Projects/Evolution/proj.android/../../../cocos2d-x/cocos2dx/textures/CCTextureAtlas.cpp:478
Stack frame #04  pc 0029bbf8  /data/app-lib//libgame.so (cocos2d::CCSpriteBatchNode::increaseAtlasCapacity()+96): Routine cocos2d::CCSpriteBatchNode::increaseAtlasCapacity() at /Users/.../Projects/cocos2d-x/Projects/Evolution/proj.android/../../../cocos2d-x/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp:420
Stack frame #05  pc 0029c6d0  /data/app-lib//libgame.so (cocos2d::CCSpriteBatchNode::appendChild(cocos2d::CCSprite*)+200): Routine cocos2d::CCSpriteBatchNode::appendChild(cocos2d::CCSprite*) at /Users/.../Projects/cocos2d-x/Projects/Evolution/proj.android/../../../cocos2d-x/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp:603
Stack frame #06  pc 0029ab98  /data/app-lib//libgame.so (cocos2d::CCSpriteBatchNode::addChild(cocos2d::CCNode*, int, int)+244): Routine cocos2d::CCSpriteBatchNode::addChild(cocos2d::CCNode*, int, int) at /Users/.../Projects/cocos2d-x/Projects/Evolution/proj.android/../../../cocos2d-x/cocos2dx/sprite_nodes/CCSpriteBatchNode.cpp:181
Stack frame #07  pc 00246ed4  /data/app-lib//libgame.so (cocos2d::CCLabelBMFont::createFontChars()+3192): Routine cocos2d::CCLabelBMFont::createFontChars() at ../../../cocos2d-x/cocos2dx/label_nodes/CCLabelBMFont.cpp:675

Any ideas how to get around this?
Thanks

signal 11 (SIGSEGV), I think it’s related to memory,why not show your code?

Hi,

I may have discovered the source of the problem, but not really sure how to properly solve the issue.
Here’s how I init the label:

    text = CCLabelBMFont::create( INIT_STRING, FONT_BMFONT, textWidth);
    text->setScale(0.4f);
    text->setAnchorPoint( ccp(0.5,0.5));
    text->setPosition( ccp( textXPosition, boxHeight/2));
    text->setColor( ccc3(0, 0, 0));
    addChild(text);

And then I update it with:

 text->setString(MESSAGE_0);

If INIT_STRING is “” (empty string) then there’s a chance that it will crash in resizeCapacity() as CCLabelBMFont is readjusting in setString().
If INIT_STRING is a long string of junk (e.g. “0123456789 0132456789013564 5646”) and as long as that string is longer than the string set in setString(), then the crash never happens because the texture is never adjusted with resizeCapacity(). I think there might be a problem in resizeCapacity(). A similar problem was described with it here: http://cocos2d-x.org/forums/6/topics/36099?r=36144#message-36144

There’s still something wrong in 3.1.1 I think. I’ve tried initializing with a long junk string, but It looks like the only way I can get around it completely is to destroy the Label and recreate it with the new text. I’m getting it on the iOS emulator atm, haven’t tested it on Android yet.