Projects > cpp > Issues > Bug #2535

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

CCTouchScriptHandlerEntry will release twice lua reference

Bug #2535 [Closed]
alexcheng 2013-08-18 03:48 . Updated almost 3 years ago

In CCScriptSupport.cpp
CCTouchScriptHandlerEntry::~CCTouchScriptHandlerEntry(void)
{
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nHandler);
LUALOG("[LUA] Remove touch event handler: %d", m_nHandler);
}

the CCTouchScriptHandlerEntry parent class is CCScriptHandlerEntry:
CCScriptHandlerEntry::~CCScriptHandlerEntry(void)
{
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nHandler);
}

when CCTouchScriptHandlerEntry is destructed ,the nHandler will be twice call “removeScriptHandler”, and lua virtual machine maybe crashed.

it should be fixed as below:
`CCScriptHandlerEntry::~CCScriptHandlerEntry(void)
{
if (m_nHandler)
{
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nHandler);
m_nHandler=0;
}
}

CCTouchScriptHandlerEntry::~CCTouchScriptHandlerEntry(void)
{
if (m_nHandler)
{
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nHandler);
m_nHandler=0;
LUALOG("[LUA] Remove touch event handler: %d", m_nHandler);
}

}
`

dualface 2013-08-20 07:13

You are right.

alexcheng 2013-09-11 06:58

I think the issue didn’t be fixed.
m_nHandler must be set NULL,like this:

if (m_nHandler) {
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nHandler);
m_nHandler=0;
}

dumganhar 2014-02-21 01:55
  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset commit:25d314a30ff9a6ec27febec4db281ac1ec14847e.

Atom PDF

Status:Closed
Start date:2013-08-18
Priority:High
Due date:
Assignee:-
% Done:

100%

Category:lua
Target version:-

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.