Skip to content

Commit

Permalink
fix endless loop when dimensions that are not enough to fit one chara…
Browse files Browse the repository at this point in the history
…cter
  • Loading branch information
WenhaiLin committed Oct 8, 2014
1 parent 442f767 commit 8ea473d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
8 changes: 6 additions & 2 deletions cocos/2d/CCLabelTextFormatter.cpp
Expand Up @@ -151,16 +151,20 @@ bool LabelTextFormatter::multilineText(Label *theLabel)
else
{
StringUtils::trimUTF16Vector(last_word);
if (isStartOfLine)
last_word.push_back(character);

last_word.push_back('\n');

multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end());
last_word.clear();
if (!isStartOfLine)
--j;

isStartOfWord = false;
isStartOfLine = false;
startOfWord = -1;
startOfLine = -1;
--j;
}
}
else
Expand Down
21 changes: 20 additions & 1 deletion tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp
Expand Up @@ -80,7 +80,8 @@ static std::function<Layer*()> createFunctions[] =
CL(LabelIssue4428Test),
CL(LabelIssue4999Test),
CL(LabelLineHeightTest),
CL(LabelAdditionalKerningTest)
CL(LabelAdditionalKerningTest),
CL(LabelIssue8492Test)
};

#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
Expand Down Expand Up @@ -1814,3 +1815,21 @@ std::string LabelAdditionalKerningTest::subtitle() const
{
return "Testing additional kerning of label";
}

LabelIssue8492Test::LabelIssue8492Test()
{
auto label = Label::createWithBMFont("fonts/bitmapFontChinese.fnt", "中国中国中国中国中国");
label->setDimensions(5,100);
label->setPosition(VisibleRect::center());
addChild(label);
}

std::string LabelIssue8492Test::title() const
{
return "Reorder issue #8492";
}

std::string LabelIssue8492Test::subtitle() const
{
return "Work fine when dimensions are not enough to fit one character";
}
11 changes: 11 additions & 0 deletions tests/cpp-tests/Classes/LabelTest/LabelTestNew.h
Expand Up @@ -509,6 +509,17 @@ class LabelAdditionalKerningTest : public AtlasDemoNew
Label* label;
};

class LabelIssue8492Test : public AtlasDemoNew
{
public:
CREATE_FUNC(LabelIssue8492Test);

LabelIssue8492Test();

virtual std::string title() const override;
virtual std::string subtitle() const override;
};

// we don't support linebreak mode

#endif

0 comments on commit 8ea473d

Please sign in to comment.