Skip to content

Commit 67fde78

Browse files
dzj0821minggo
authored andcommitted
fix crash when plist filename hasn't suffix (#19999)
1 parent c840544 commit 67fde78

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cocos/2d/CCSpriteFrameCache.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,10 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist)
389389

390390
// remove .xxx
391391
size_t startPos = texturePath.find_last_of('.');
392-
texturePath = texturePath.erase(startPos);
392+
if(startPos != string::npos)
393+
{
394+
texturePath = texturePath.erase(startPos);
395+
}
393396

394397
// append .png
395398
texturePath = texturePath.append(".png");
@@ -691,8 +694,11 @@ bool SpriteFrameCache::reloadTexture(const std::string& plist)
691694

692695
// remove .xxx
693696
size_t startPos = texturePath.find_last_of('.');
694-
texturePath = texturePath.erase(startPos);
695-
697+
if(startPos != string::npos)
698+
{
699+
texturePath = texturePath.erase(startPos);
700+
}
701+
696702
// append .png
697703
texturePath = texturePath.append(".png");
698704
}

0 commit comments

Comments
 (0)