Skip to content

Commit 19ea797

Browse files
perminovVSminggo
authored andcommitted
Fix crash TextFieldTTF::setCursorFromPoint (cocos2d#18159)
A similar problem of cocos2d#15926
1 parent 40ec511 commit 19ea797

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

cocos/2d/CCTextFieldTTF.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,17 @@ void TextFieldTTF::setCursorFromPoint(const Vec2 &point, const Camera* camera)
382382
int latterPosition = 0;
383383
for (; latterPosition < _lengthOfString; ++latterPosition)
384384
{
385-
if (_lettersInfo[latterPosition].valid)
385+
if (_lettersInfo[latterPosition].valid && _lettersInfo[latterPosition].atlasIndex >= 0)
386386
{
387387
auto sprite = getLetter(latterPosition);
388-
rect.size = sprite->getContentSize();
389-
if (isScreenPointInRect(point, camera, sprite->getWorldToNodeTransform(), rect, nullptr))
388+
if (sprite)
390389
{
391-
setCursorPosition(latterPosition);
392-
break;
390+
rect.size = sprite->getContentSize();
391+
if (isScreenPointInRect(point, camera, sprite->getWorldToNodeTransform(), rect, nullptr))
392+
{
393+
setCursorPosition(latterPosition);
394+
break;
395+
}
393396
}
394397
}
395398
}

0 commit comments

Comments
 (0)