From 68eaa746eac3f15f3ff82f6e075af56eb0c2ea44 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 20 Feb 2014 21:58:20 +0800 Subject: [PATCH] closed #2535: TouchScriptHandlerEntry will release twice lua reference --- cocos/2d/CCScriptSupport.cpp | 9 ++++++--- cocos/2d/CCScriptSupport.h | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cocos/2d/CCScriptSupport.cpp b/cocos/2d/CCScriptSupport.cpp index 972540b608..36ec7a2db8 100644 --- a/cocos/2d/CCScriptSupport.cpp +++ b/cocos/2d/CCScriptSupport.cpp @@ -53,7 +53,12 @@ ScriptHandlerEntry* ScriptHandlerEntry::create(int handler) ScriptHandlerEntry::~ScriptHandlerEntry(void) { - ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptHandler(_handler); + if (_handler != 0 ) + { + ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptHandler(_handler); + LUALOG("[LUA] Remove event handler: %d", _handler); + _handler = 0; + } } // #pragma mark - @@ -101,8 +106,6 @@ TouchScriptHandlerEntry* TouchScriptHandlerEntry::create(int handler, TouchScriptHandlerEntry::~TouchScriptHandlerEntry(void) { - ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptHandler(_handler); - LUALOG("[LUA] Remove touch event handler: %d", _handler); } bool TouchScriptHandlerEntry::init(bool isMultiTouches, int priority, bool swallowsTouches) diff --git a/cocos/2d/CCScriptSupport.h b/cocos/2d/CCScriptSupport.h index 0028365a67..aa49828ad5 100644 --- a/cocos/2d/CCScriptSupport.h +++ b/cocos/2d/CCScriptSupport.h @@ -62,7 +62,7 @@ public: * @js NA * @lua NA */ - ~ScriptHandlerEntry(void); + virtual ~ScriptHandlerEntry(); int getHandler(void) { return _handler; @@ -103,7 +103,7 @@ public: * @js NA * @lua NA */ - ~SchedulerScriptHandlerEntry(void); + virtual ~SchedulerScriptHandlerEntry(); /** * @js NA * @lua NA @@ -162,7 +162,7 @@ public: * @js NA * @lua NA */ - ~TouchScriptHandlerEntry(void); + virtual ~TouchScriptHandlerEntry(); /** * @js NA * @lua NA