Well, this one was really hard to find took me at most 5 hours to get to the point where I was about to pull out my hair!
Both the Cocos2d-x tests and my own little game would completely lock up when CCLabelBMFont was used. This did however only happen when I was NOT using the debug versions of the Cocos2d-x library and apps, which made the lockup hard to investigate because of the missing debugging information and inability to step through the code using the debugger. No stracktraces either, and I donāt have tools to inspect memory and program data, so thatās why it was really hard. Running the non-debug version with the debugger would not help either, because the problem would not show up at those times.
After a while of putting in lots and lots of oldskool printfās and MessageBoxes, I succeeded in pinpointing the location of the lockup, which happened to be in $cocos2d_root/cocos2dx/label_nodes/CCLabelBMFont.cpp
Inside this file, thereās a method named parseConfigFile(const char*). This method is indirectly used by CCBitmapFontAtlas::bitmapFontAtlasWithString(ā¦) to load the .fnt file. It does that using C functions, like memset, memcpy and strchr.
Iām still not exactly sure why it happens, but it looks like the use of memset causes a bunch of too many characters to be deleted at certain times, causing the very last āā to be removed, causing āleftSizeā to stay above a certain value and in turn causing the while-loop to keep running and never exit. Et voila, the program locks up because of this series of very unfortunate events
The font files for my game are generated by the Hiero font generator and the programs were all compiled and executed on Windows Vista, using Visual Studio 2008 and standard program optimization (no agressive optimization settings). As of yet, I have no idea if this bug shows up on other platforms.
Iāve fixed it in the attached patch. If you would like to see the bug in action before patching up the Git version, please ask and Iāll whip up a small sample program that shows the bug in action.
CCLabelBMFont_lockup.patch.zip (1.2 KB)