From afe49b3a2bb0c794818e853191067b9782a95c17 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Thu, 16 Jan 2014 11:47:06 +0800 Subject: [PATCH 1/3] 1.Fix crash bug when using unknown character 2.Fix text align mistake --- cocos/2d/CCFontAtlas.cpp | 1 + cocos/2d/CCLabelTextFormatter.cpp | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/cocos/2d/CCFontAtlas.cpp b/cocos/2d/CCFontAtlas.cpp index 4d35ce980d..9282956d03 100644 --- a/cocos/2d/CCFontAtlas.cpp +++ b/cocos/2d/CCFontAtlas.cpp @@ -100,6 +100,7 @@ bool FontAtlas::getLetterDefinitionForChar(unsigned short letteCharUTF16, FontL } else { + outDefinition.validDefinition = false; return false; } } diff --git a/cocos/2d/CCLabelTextFormatter.cpp b/cocos/2d/CCLabelTextFormatter.cpp index 956c5c3bb1..b4977c8a92 100644 --- a/cocos/2d/CCLabelTextFormatter.cpp +++ b/cocos/2d/CCLabelTextFormatter.cpp @@ -241,8 +241,6 @@ bool LabelTextFormatter::alignText(LabelTextFormatProtocol *theLabel) continue; } int index = static_cast(i + lineLength - 1 + lineNumber); - if(currentChar == 0) - index -= 1; if (index < 0) continue; LetterInfo* info = &leterInfo->at( index ); From 18bd9784805433768a51e729d7b79fb3a3a9b493 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Thu, 16 Jan 2014 14:37:07 +0800 Subject: [PATCH 2/3] 1.add label crash test 2.fix lose char when label have unknown character. --- cocos/2d/CCLabelTextFormatter.cpp | 12 ++++++--- .../Classes/LabelTest/LabelTestNew.cpp | 25 ++++++++++++++++++- .../TestCpp/Classes/LabelTest/LabelTestNew.h | 10 ++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/cocos/2d/CCLabelTextFormatter.cpp b/cocos/2d/CCLabelTextFormatter.cpp index b4977c8a92..550d017beb 100644 --- a/cocos/2d/CCLabelTextFormatter.cpp +++ b/cocos/2d/CCLabelTextFormatter.cpp @@ -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) { diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp index d779ae6a86..2a3334875f 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp @@ -66,7 +66,8 @@ static std::function 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崩溃34324324", 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 "Should not crash when using unknown character."; +} diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h index ad6b53211c..b0b120b063 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h @@ -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 From 547ab3ef0a100bb3ab969af1a60c06240b6e9404 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Thu, 16 Jan 2014 15:07:20 +0800 Subject: [PATCH 3/3] update subtitle. --- samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp index 2a3334875f..c28585dfbe 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp @@ -1250,7 +1250,7 @@ LabelCrashTest::LabelCrashTest() TTFConfig ttfConfig("fonts/arial.ttf", 80, GlyphCollection::DYNAMIC,nullptr,true); - auto label1 = Label::createWithTTF(ttfConfig,"Test崩溃34324324", TextHAlignment::CENTER, size.width); + 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); @@ -1263,5 +1263,5 @@ std::string LabelCrashTest::title() const std::string LabelCrashTest::subtitle() const { - return "Should not crash when using unknown character."; + return "Not crash and show [Test123] when using unknown character."; }