From e7e365a00fea7023d78f59650964686a7ebc8412 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 28 Jun 2016 11:59:55 +0800 Subject: [PATCH] Fix window.close crash in JSB --- cocos/scripting/js-bindings/manual/ScriptingCore.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp index 1a6db4248c..b789aa03d2 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp @@ -386,7 +386,13 @@ bool JSB_core_restartVM(JSContext *cx, uint32_t argc, jsval *vp) bool JSB_closeWindow(JSContext *cx, uint32_t argc, jsval *vp) { - ScriptingCore::getInstance()->cleanup(); + EventListenerCustom* _event = Director::getInstance()->getEventDispatcher()->addCustomEventListener(Director::EVENT_AFTER_DRAW, [&](EventCustom *event) { + Director::getInstance()->getEventDispatcher()->removeEventListener(_event); + _event->release(); + + ScriptingCore::getInstance()->cleanup(); + }); + _event->retain(); Director::getInstance()->end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0);