Merge pull request #11105 from pipu/TextAtlas_parse_avoid_crash

Avoid crash during parse TextAtlas.
This commit is contained in:
minggo 2015-03-25 13:36:28 +08:00
commit 326233ab02
1 changed files with 31 additions and 8 deletions

View File

@ -247,19 +247,42 @@ namespace cocostudio
case 0: case 0:
{ {
const char* cmfPath = cmftDic->path()->c_str(); const char* cmfPath = cmftDic->path()->c_str();
std::string stringValue = options->stringValue()->c_str();
int itemWidth = options->itemWidth(); bool fileExist = false;
int itemHeight = options->itemHeight(); std::string errorFilePath = "";
labelAtlas->setProperty(stringValue,
cmfPath, if (FileUtils::getInstance()->isFileExist(cmfPath))
itemWidth, {
itemHeight, fileExist = true;
options->startCharMap()->c_str());
std::string stringValue = options->stringValue()->c_str();
int itemWidth = options->itemWidth();
int itemHeight = options->itemHeight();
labelAtlas->setProperty(stringValue,
cmfPath,
itemWidth,
itemHeight,
options->startCharMap()->c_str());
}
else
{
errorFilePath = cmfPath;
fileExist = false;
}
if (!fileExist)
{
auto label = Label::create();
label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString());
labelAtlas->addChild(label);
}
break; break;
} }
case 1: case 1:
CCLOG("Wrong res type of LabelAtlas!"); CCLOG("Wrong res type of LabelAtlas!");
break; break;
default: default:
break; break;
} }