提交 bc5f5991 编写于 作者: cocos2d-lua.org's avatar cocos2d-lua.org

trucate label text if too long

上级 1d886617
......@@ -450,6 +450,7 @@ bool Label::setBMFontFilePath(const std::string& bmfontFilePath, const Vec2& ima
return true;
}
#define CC_LABEL_MAX_LENGTH ((1 << 16) / 2)
void Label::setString(const std::string& text)
{
if (text.compare(_originalUTF8String))
......@@ -462,6 +463,12 @@ void Label::setString(const std::string& text)
{
_currentUTF16String = utf16String;
}
if (_currentUTF16String.length() > CC_LABEL_MAX_LENGTH)
{
cocos2d::log("Error: Label text is too long %lu > %d and it will be truncated!", _currentUTF16String.length(), CC_LABEL_MAX_LENGTH);
_currentUTF16String = _currentUTF16String.substr(0, CC_LABEL_MAX_LENGTH);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册