mirror of https://github.com/axmolengine/axmol.git
Merge pull request #13296 from WenhaiLin/v3.8-label-crash-mac
Label:Fixed crash cause by access an invalid address
This commit is contained in:
commit
c65f09f63e
|
@ -66,6 +66,8 @@ public:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
CREATE_FUNC(LabelLetter);
|
||||
|
||||
virtual void updateTransform() override
|
||||
{
|
||||
if (isDirty())
|
||||
|
@ -745,17 +747,18 @@ void Label::updateQuads()
|
|||
}
|
||||
|
||||
for (int ctr = 0; ctr < _lengthOfString; ++ctr)
|
||||
{
|
||||
if (_lettersInfo[ctr].valid)
|
||||
{
|
||||
auto& letterDef = _fontAtlas->_letterDefinitions[_lettersInfo[ctr].utf16Char];
|
||||
|
||||
if (letterDef.validDefinition)
|
||||
{
|
||||
_reusedRect.size.height = letterDef.height;
|
||||
_reusedRect.size.width = letterDef.width;
|
||||
_reusedRect.origin.x = letterDef.U;
|
||||
_reusedRect.origin.y = letterDef.V;
|
||||
|
||||
auto py = _lettersInfo[ctr].positionY + _letterOffsetY;
|
||||
if (_labelHeight > 0.f) {
|
||||
if (py > _tailoredTopY)
|
||||
{
|
||||
auto clipTop = py - _tailoredTopY;
|
||||
|
@ -767,6 +770,7 @@ void Label::updateQuads()
|
|||
{
|
||||
_reusedRect.size.height = (py < _tailoredBottomY) ? 0.f : (py - _tailoredBottomY);
|
||||
}
|
||||
}
|
||||
|
||||
if (_reusedRect.size.height > 0.f && _reusedRect.size.width > 0.f)
|
||||
{
|
||||
|
@ -1389,26 +1393,39 @@ Sprite * Label::getLetter(int letterIndex)
|
|||
uvRect.origin.y = letterDef.V;
|
||||
|
||||
if (letter == nullptr)
|
||||
{
|
||||
if (letterDef.width <= 0.f || letterDef.height <= 0.f)
|
||||
{
|
||||
letter = LabelLetter::create();
|
||||
}
|
||||
else
|
||||
{
|
||||
letter = LabelLetter::createWithTexture(_fontAtlas->getTexture(textureID), uvRect);
|
||||
letter->setTextureAtlas(_batchNodes.at(textureID)->getTextureAtlas());
|
||||
letter->setAtlasIndex(letterInfo.atlasIndex);
|
||||
|
||||
auto px = letterInfo.positionX + uvRect.size.width / 2 + _linesOffsetX[letterInfo.lineIndex];
|
||||
auto py = letterInfo.positionY - uvRect.size.height / 2 + _letterOffsetY;
|
||||
letter->setPosition(px,py);
|
||||
letter->setOpacity(_realOpacity);
|
||||
addChild(letter);
|
||||
}
|
||||
|
||||
addChild(letter);
|
||||
_letters[letterIndex] = letter;
|
||||
}
|
||||
else if (contentDirty)
|
||||
{
|
||||
if (letterDef.width <= 0.f || letterDef.height <= 0.f)
|
||||
{
|
||||
letter->setTextureAtlas(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
letter->setTexture(_fontAtlas->getTexture(textureID));
|
||||
letter->setTextureRect(uvRect, false, uvRect.size);
|
||||
letter->setTextureAtlas(_batchNodes.at(textureID)->getTextureAtlas());
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (false);
|
||||
|
||||
return letter;
|
||||
|
|
Loading…
Reference in New Issue