From eda9846e6f7aaee1e7adeac2aeb94fa6293253ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=B1=EB=82=99=ED=98=B8?= Date: Thu, 8 Aug 2013 18:36:56 +0900 Subject: [PATCH] DelegateProtocol is weak-referenced again --- extensions/AssetsManager/AssetsManager.cpp | 21 ++++++--------------- extensions/AssetsManager/AssetsManager.h | 3 ++- tools/tojs/cocos2dx_extension.ini | 1 + 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/extensions/AssetsManager/AssetsManager.cpp b/extensions/AssetsManager/AssetsManager.cpp index 8060f86445..04d1fde900 100644 --- a/extensions/AssetsManager/AssetsManager.cpp +++ b/extensions/AssetsManager/AssetsManager.cpp @@ -83,6 +83,7 @@ AssetsManager::AssetsManager(const char* packageUrl/* =NULL */, const char* vers , _connectionTimeout(0) , _delegate(NULL) , _isDownloading(false) +, _shouldDeleteDelegateWhenExit(false) { checkStoragePath(); _schedule = new Helper(); @@ -90,14 +91,14 @@ AssetsManager::AssetsManager(const char* packageUrl/* =NULL */, const char* vers AssetsManager::~AssetsManager() { - if (_delegate) - { - _delegate->release(); - } if (_schedule) { _schedule->release(); } + if (_shouldDeleteDelegateWhenExit) + { + delete _delegate; + } } void AssetsManager::checkStoragePath() @@ -505,17 +506,7 @@ void AssetsManager::deleteVersion() void AssetsManager::setDelegate(AssetsManagerDelegateProtocol *delegate) { - if (_delegate) - { - _delegate->release(); - } - _delegate = delegate; - - if (_delegate) - { - _delegate->retain(); - } } void AssetsManager::setConnectionTimeout(unsigned int timeout) @@ -661,8 +652,8 @@ AssetsManager* AssetsManager::create(const char* packageUrl, const char* version auto* manager = new AssetsManager(packageUrl,versionFileUrl,storagePath); auto* delegate = new DelegateProtocolImpl(errorCallback,progressCallback,successCallback); - delegate->autorelease(); manager->setDelegate(delegate); + manager->_shouldDeleteDelegateWhenExit = true; return manager; } diff --git a/extensions/AssetsManager/AssetsManager.h b/extensions/AssetsManager/AssetsManager.h index a1e81302c1..8e0bcd859a 100644 --- a/extensions/AssetsManager/AssetsManager.h +++ b/extensions/AssetsManager/AssetsManager.h @@ -211,12 +211,13 @@ private: AssetsManagerDelegateProtocol *_delegate; bool _isDownloading; + bool _shouldDeleteDelegateWhenExit; std::string key_of_version() const; std::string key_of_downloaded_version() const; }; -class AssetsManagerDelegateProtocol : public Object +class AssetsManagerDelegateProtocol { public: /* @brief Call back function for error diff --git a/tools/tojs/cocos2dx_extension.ini b/tools/tojs/cocos2dx_extension.ini index 6c812165bc..d620fb6753 100644 --- a/tools/tojs/cocos2dx_extension.ini +++ b/tools/tojs/cocos2dx_extension.ini @@ -44,6 +44,7 @@ skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getC EditBox::[(g|s)etDelegate ^keyboard.* touchDownAction getScriptEditBoxHandler registerScriptEditBoxHandler unregisterScriptEditBoxHandler], TableView::[create (g|s)etDataSource$ (g|s)etDelegate], AssetsManager::[setDelegate], + AssetsManagerDelegateProtocol::[*], Control::[removeHandleOfControlEvent addHandleOfControlEvent] rename_functions = CCBReader::[getAnimationManager=getActionManager setAnimationManager=setActionManager],