问题环境:
单行(多行没测)
设置范围 TextFieldTTF::setDimensions
初始化光标 TextFieldTTF::initCursorSprite
使用 TextFieldTTF::setPlaceHolder
或者 TextFieldTTF::setString
或者使用 手动输入 TextFieldTTF::insertText
存在 字符串的长度超过设置宽度的情况
问题:
调用 TextFieldTTF::setCursorFromPoint 设置光标位置时,有可能出现崩溃
问题代码:
void TextFieldTTF::setCursorFromPoint(const Vec2 &point, const Camera* camera)
{
......
int latterPosition = 0;
for (; latterPosition < _lengthOfString; ++latterPosition)
{
if (_lettersInfo[latterPosition].valid) //_lettersInfo中,超过 setDimensions 设置范围的字符,数据的valid是true,但是,其他数据是有问题的,其中 atlasIndex 是小于0的的数字
{
auto sprite = getLetter(latterPosition); //getLetter中使用了 atlasIndex =》 letter->setAtlasIndex(letterInfo.atlasIndex); 【letter 是Sprite】
rect.size = sprite->getContentSize();
if (isScreenPointInRect(point, camera, sprite->getWorldToNodeTransform(), rect, nullptr))
{
setCursorPosition(latterPosition);
break;
}
}
}
......
}
TextureAtlas ,使用了 Sprite的 atlasIndex,存在小于0的判定
void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, ssize_t index) { CCASSERT( index >= 0 && index < _capacity, "updateQuadWithTexture: Invalid index");
_totalQuads = MAX( index+1, _totalQuads);
_quads[index] = *quad;
_dirty = true;
}