Skip to content

Commit 7618126

Browse files
author
long
committed
issue cocos2d#1108: improve restart method, it can run in the appDelegate.cpp, but can not run in js code
1 parent e3a8640 commit 7618126

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

frameworks/js-bindings/bindings/manual/ScriptingCore.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ bool JSB_restartGame(JSContext *cx, uint32_t argc, jsval *vp)
377377
JS_SET_RVAL(cx, vp, JSVAL_VOID);
378378
JSB_PRECONDITION2(argc==0, cx, false, "Invalid number of arguments in executeScript");
379379
ScriptingCore::getInstance()->reset();
380-
}
380+
return true;
381+
};
381382

382383
bool JSB_core_restartVM(JSContext *cx, uint32_t argc, jsval *vp)
383384
{
@@ -731,8 +732,23 @@ bool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* cx)
731732

732733
void ScriptingCore::reset()
733734
{
735+
auto director = Director::getInstance();
736+
FontFNT::purgeCachedData();
737+
if (director->getOpenGLView())
738+
{
739+
SpriteFrameCache::getInstance()->removeSpriteFrames();
740+
director->getTextureCache()->removeAllTextures();
741+
}
742+
FileUtils::getInstance()->purgeCachedEntries();
743+
director->getScheduler()->unscheduleAll();
744+
734745
cleanup();
735-
start();
746+
747+
this->addRegisterCallback(registerDefaultClasses);
748+
this->_runLoop = new SimpleRunLoop();
749+
750+
Application::getInstance()->run();
751+
//start();
736752
}
737753

738754
ScriptingCore::~ScriptingCore()
@@ -768,6 +784,7 @@ void ScriptingCore::cleanup()
768784

769785
_js_global_type_map.clear();
770786
filename_script.clear();
787+
registrationList.clear();
771788
}
772789

773790
void ScriptingCore::reportError(JSContext *cx, const char *message, JSErrorReport *report)

0 commit comments

Comments
 (0)