diff --git a/extensions/AssetsManager/AssetsManager.cpp b/extensions/AssetsManager/AssetsManager.cpp index 15acacb49e..61b9081121 100644 --- a/extensions/AssetsManager/AssetsManager.cpp +++ b/extensions/AssetsManager/AssetsManager.cpp @@ -654,6 +654,7 @@ AssetsManager* AssetsManager::create(const char* packageUrl, const char* version auto* delegate = new DelegateProtocolImpl(errorCallback,progressCallback,successCallback); manager->setDelegate(delegate); manager->_shouldDeleteDelegateWhenExit = true; + manager->autorelease(); return manager; } diff --git a/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp b/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp index bcb045c351..4768e7d038 100644 --- a/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp +++ b/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.cpp @@ -85,8 +85,6 @@ UpdateLayer::UpdateLayer() UpdateLayer::~UpdateLayer() { - AssetsManager *pAssetsManager = getAssetsManager(); - CC_SAFE_DELETE(pAssetsManager); } void UpdateLayer::update(cocos2d::Object *pSender) @@ -141,6 +139,14 @@ bool UpdateLayer::init() { Layer::init(); + /** Creates assets manager */ + pAssetsManager = new AssetsManager("https://raw.github.com/minggo/AssetsManagerTest/master/package.zip", + "https://raw.github.com/minggo/AssetsManagerTest/master/version", + pathToSave.c_str()); + pAssetsManager->setDelegate(this); + pAssetsManager->setConnectionTimeout(3); + addChild(pAssetsManager); + createDownloadedDir(); Size size = Director::getInstance()->getWinSize(); @@ -164,22 +170,6 @@ bool UpdateLayer::init() return true; } -AssetsManager* UpdateLayer::getAssetsManager() -{ - static AssetsManager *pAssetsManager = NULL; - - if (! pAssetsManager) - { - pAssetsManager = new AssetsManager("https://raw.github.com/minggo/AssetsManagerTest/master/package.zip", - "https://raw.github.com/minggo/AssetsManagerTest/master/version", - pathToSave.c_str()); - pAssetsManager->setDelegate(this); - pAssetsManager->setConnectionTimeout(3); - } - - return pAssetsManager; -} - void UpdateLayer::createDownloadedDir() { pathToSave = FileUtils::getInstance()->getWritablePath(); diff --git a/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.h b/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.h index a6518be098..7fcf54741d 100644 --- a/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.h +++ b/samples/Cpp/AssetsManagerTest/Classes/AppDelegate.h @@ -60,7 +60,7 @@ public: virtual void onSuccess(); private: - cocos2d::extension::AssetsManager* getAssetsManager(); + cocos2d::extension::AssetsManager* pAssetsManager; void createDownloadedDir(); cocos2d::MenuItemFont *pItemEnter;