Fixed FontAtlasCache::purgeCachedData might cause crash.

This commit is contained in:
WenhaiLin 2015-08-05 14:12:02 +08:00
parent 8cdcade07a
commit 2c220092e6
3 changed files with 40 additions and 1 deletions

View File

@ -39,7 +39,8 @@ std::unordered_map<std::string, FontAtlas *> FontAtlasCache::_atlasMap;
void FontAtlasCache::purgeCachedData()
{
for (auto & atlas:_atlasMap)
auto atlasMapCopy = _atlasMap;
for (auto&& atlas : atlasMapCopy)
{
atlas.second->purgeTexturesAtlas();
}

View File

@ -1,6 +1,7 @@
#include "LabelTestNew.h"
#include "../testResource.h"
#include "renderer/CCRenderer.h"
#include "2d/CCFontAtlasCache.h"
USING_NS_CC;
using namespace ui;
@ -85,6 +86,7 @@ NewLabelTests::NewLabelTests()
ADD_TEST_CASE(LabelIssue11585Test);
ADD_TEST_CASE(LabelFullTypeFontTest);
ADD_TEST_CASE(LabelIssue10688Test);
ADD_TEST_CASE(LabelIssue13202Test);
};
LabelTTFAlignmentNew::LabelTTFAlignmentNew()
@ -2058,3 +2060,28 @@ std::string LabelIssue10688Test::subtitle() const
{
return "The MenuItemLabel should be displayed in the middle of the screen.";
}
LabelIssue13202Test::LabelIssue13202Test()
{
auto center = VisibleRect::center();
auto label = Label::createWithTTF("asdfghjklzxcvbnmqwertyuiop", "fonts/arial.ttf", 150);
label->setPosition(center);
addChild(label);
label->getContentSize();
label->setString("A");
this->scheduleOnce([](float dt){
FontAtlasCache::purgeCachedData();
}, 0.15f, "FontAtlasCache::purgeCachedData");
}
std::string LabelIssue13202Test::title() const
{
return "Test for Issue #13202";
}
std::string LabelIssue13202Test::subtitle() const
{
return "FontAtlasCache::purgeCachedData should not cause crash.";
}

View File

@ -658,4 +658,15 @@ public:
virtual std::string subtitle() const override;
};
class LabelIssue13202Test : public AtlasDemoNew
{
public:
CREATE_FUNC(LabelIssue13202Test);
LabelIssue13202Test();
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
#endif