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)