mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5082 from Dhilan007/develop_label
closed #3726:Fix crash when using unknown character.
This commit is contained in:
commit
21dc91bf78
|
@ -100,6 +100,7 @@ bool FontAtlas::getLetterDefinitionForChar(unsigned short letteCharUTF16, FontL
|
|||
}
|
||||
else
|
||||
{
|
||||
outDefinition.validDefinition = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,20 +63,24 @@ bool LabelTextFormatter::multilineText(LabelTextFormatProtocol *theLabel)
|
|||
{
|
||||
LetterInfo* info = &leterInfo->at(j+skip);
|
||||
|
||||
unsigned int justSkipped = 0;
|
||||
unsigned int justSkipped = 0;
|
||||
|
||||
while (info->def.validDefinition == false)
|
||||
{
|
||||
justSkipped++;
|
||||
info = &leterInfo->at( j+skip+justSkipped );
|
||||
tIndex = j+skip+justSkipped;
|
||||
if(tIndex < strLen)
|
||||
info = &leterInfo->at( tIndex );
|
||||
else
|
||||
break;
|
||||
}
|
||||
skip += justSkipped;
|
||||
tIndex = j + skip;
|
||||
|
||||
if (i >= stringLength)
|
||||
if (tIndex >= stringLength)
|
||||
break;
|
||||
|
||||
unsigned short character = strWhole[i];
|
||||
unsigned short character = strWhole[tIndex];
|
||||
|
||||
if (!isStartOfWord)
|
||||
{
|
||||
|
@ -241,8 +245,6 @@ bool LabelTextFormatter::alignText(LabelTextFormatProtocol *theLabel)
|
|||
continue;
|
||||
}
|
||||
int index = static_cast<int>(i + lineLength - 1 + lineNumber);
|
||||
if(currentChar == 0)
|
||||
index -= 1;
|
||||
if (index < 0) continue;
|
||||
|
||||
LetterInfo* info = &leterInfo->at( index );
|
||||
|
|
|
@ -66,7 +66,8 @@ static std::function<Layer*()> createFunctions[] =
|
|||
CL(LabelTTFUnicodeNew),
|
||||
CL(LabelBMFontTestNew),
|
||||
CL(LabelTTFDistanceField),
|
||||
CL(LabelTTFDistanceFieldEffect)
|
||||
CL(LabelTTFDistanceFieldEffect),
|
||||
CL(LabelCrashTest)
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
@ -1242,3 +1243,25 @@ std::string LabelTTFDistanceFieldEffect::subtitle() const
|
|||
{
|
||||
return "Testing effect base on DistanceField";
|
||||
}
|
||||
|
||||
LabelCrashTest::LabelCrashTest()
|
||||
{
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
|
||||
TTFConfig ttfConfig("fonts/arial.ttf", 80, GlyphCollection::DYNAMIC,nullptr,true);
|
||||
|
||||
auto label1 = Label::createWithTTF(ttfConfig,"Test崩溃123", TextHAlignment::CENTER, size.width);
|
||||
label1->setPosition( Point(size.width/2, size.height/2) );
|
||||
label1->setAnchorPoint(Point(0.5, 0.5));
|
||||
addChild(label1);
|
||||
}
|
||||
|
||||
std::string LabelCrashTest::title() const
|
||||
{
|
||||
return "New Label Crash Test";
|
||||
}
|
||||
|
||||
std::string LabelCrashTest::subtitle() const
|
||||
{
|
||||
return "Not crash and show [Test123] when using unknown character.";
|
||||
}
|
||||
|
|
|
@ -347,6 +347,16 @@ public:
|
|||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class LabelCrashTest : public AtlasDemoNew
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(LabelCrashTest);
|
||||
|
||||
LabelCrashTest();
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
// we don't support linebreak mode
|
||||
|
||||
|
|
Loading…
Reference in New Issue