From 6f17dcecf2d6aad54f1683185850445b456e8f1a Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Mon, 27 Apr 2015 11:01:47 +0800 Subject: [PATCH] Update config.json for 3rd-party-libs and SpritePolygonCache --- cocos/2d/SpritePolygon.cpp | 3 +-- cocos/2d/SpritePolygonCache.cpp | 23 ++++++++++++++++++----- cocos/2d/SpritePolygonCache.h | 11 ++++++++++- external/config.json | 2 +- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/cocos/2d/SpritePolygon.cpp b/cocos/2d/SpritePolygon.cpp index 4f93992c77..a7ccc59d0f 100644 --- a/cocos/2d/SpritePolygon.cpp +++ b/cocos/2d/SpritePolygon.cpp @@ -268,8 +268,7 @@ bool SpritePolygon::initWithMarching(const std::string &file, const cocos2d::Rec _polygonInfo = SpritePolygonCache::getInstance()->addSpritePolygonCache(file, *info); calculateUVandContentSize(); - delete _triangles.verts; - delete _triangles.indices; + delete info; #if CC_SPRITE_DEBUG_DRAW debugDraw(); #endif diff --git a/cocos/2d/SpritePolygonCache.cpp b/cocos/2d/SpritePolygonCache.cpp index 6924282e74..0b522468b6 100644 --- a/cocos/2d/SpritePolygonCache.cpp +++ b/cocos/2d/SpritePolygonCache.cpp @@ -145,14 +145,23 @@ void SpritePolygonCache::removeSpritePolygonCache(const std::string& filePath, return; if (nullptr == rect) - { - - } + return; auto infoIter = it->second.begin(); + bool exist = false; for (; infoIter != it->second.end(); infoIter++) { - //TODO: write clean up code... + if((*infoIter)->_rect.equals(*rect)) + { + exist = true; + break; + } + } + + if (exist) + { + CC_SAFE_DELETE(*infoIter); + it->second.erase(infoIter); } return; @@ -162,7 +171,11 @@ void SpritePolygonCache::removeAllSpritePolygonCache() { for (std::unordered_map::iterator it = _SpritePolygonCacheMap.begin(); it != _SpritePolygonCacheMap.end(); ++it) { - //TODO: write clean up code... + auto infoIter = it->second.begin(); + for (; infoIter != it->second.end(); infoIter++) + { + CC_SAFE_DELETE(*infoIter); + } it->second.clear(); } _SpritePolygonCacheMap.clear(); diff --git a/cocos/2d/SpritePolygonCache.h b/cocos/2d/SpritePolygonCache.h index 7d87d69bb5..0980f65697 100644 --- a/cocos/2d/SpritePolygonCache.h +++ b/cocos/2d/SpritePolygonCache.h @@ -40,8 +40,17 @@ typedef struct CC_DLL _SpritePolygonInfo { cocos2d::Rect _rect; cocos2d::TrianglesCommand::Triangles _triangles; - ~_SpritePolygonInfo(){ + ~_SpritePolygonInfo() + { + if(nullptr != _triangles.verts) + { + CC_SAFE_DELETE_ARRAY(_triangles.verts); + } + if(nullptr != _triangles.indices) + { + CC_SAFE_DELETE_ARRAY(_triangles.indices); + } } } SpritePolygonInfo; diff --git a/external/config.json b/external/config.json index 5b5dd93449..f3658624c1 100644 --- a/external/config.json +++ b/external/config.json @@ -1,5 +1,5 @@ { - "version":"v3-deps-46", + "version":"v3-deps-47", "zip_file_size":"74127526", "repo_name":"cocos2d-x-3rd-party-libs-bin", "repo_parent":"https://github.com/cocos2d/",