Skip to content

Commit

Permalink
SpriteFrameCache: fix dangling ref in `removeSpriteFramesFromTexture(…
Browse files Browse the repository at this point in the history
…)` (#2106)
  • Loading branch information
smilediver authored Aug 27, 2024
1 parent e6174ff commit ebdf2a7
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions core/2d/SpriteFrameCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,10 @@ void SpriteFrameCache::removeSpriteFramesFromTexture(Texture2D* texture)

for (auto&& iter : getSpriteFrames())
{
auto key = iter.first;
auto* frame = findFrame(key);
auto* frame = findFrame(iter.first);
if (frame && (frame->getTexture() == texture))
{
keysToRemove.emplace_back(key);
keysToRemove.emplace_back(iter.first);
}
}

Expand Down Expand Up @@ -327,8 +326,8 @@ bool SpriteFrameCache::eraseFrame(std::string_view frameName)
{
// drop SpriteFrame
const auto itFrame = _spriteFrameToSpriteSheetMap.find(frameName);
bool hint = itFrame != _spriteFrameToSpriteSheetMap.end();
if (hint)
bool found = itFrame != _spriteFrameToSpriteSheetMap.end();
if (found)
{
auto& spriteSheet = itFrame->second;
spriteSheet->full = false;
Expand All @@ -348,7 +347,7 @@ bool SpriteFrameCache::eraseFrame(std::string_view frameName)
//}
}
_spriteFrames.erase(frameName);
return hint;
return found;
}

bool SpriteFrameCache::eraseFrames(const std::vector<std::string_view>& frames)
Expand Down

0 comments on commit ebdf2a7

Please sign in to comment.