Exception : Bad Access. Place of Occurance : ScriptingCore class in executeFunctionWithOwner function at the end of ‘do’ block, bRet = JS_CallFunctionValue(cx, obj, funcVal, args, retVal) this particular line is throwing exception.
Stack Trace :
ScriptingCore::executeFunctionWithOwner() is called from ScriptingCore::handleTouchEvent().
ScriptingCore::handleTouchEvent() is called from js_EventListenerTouchOneByOne_create() function of jsb_event_dispatcher_manual.cpp class.
Steps to Reproduce :
Launch a game which has multiple touch action.
Start playing the game.
At some point in the game level app crashes.
This is an unfortunate situation and I used to face it frequently too. It happens only on iOS and not on Android. The reason is associated with garbage collection being triggered at the time of drag and that also garbage collects touch related objects.
Fortunately, cocos2d-x allows you to manually control garbage collection. The solution I came up with is this:
on every onTouchEnded event, set timeout to trigger garbage collection after 1s.
on every onTouchBegan, cancel the timeout to garbage collect