I am working on a hot update feature for my game that need to restart the whole cocos2d engine.
I have created a thread here: http://www.cocos2d-x.org/boards/6/topics/34873
I created this thread here in jsb zone to discuss the right way to restart a scripting VM.
Yes, there is a binding function called restartVM may fit my needs. Unfortunately, callingrestartVM only will cause a crash there.
After I looked the implementation of restartVM, I think a crash is unavoidable:
restartVM invoke reset method of ScriptCore which will destroy and recreate entire global object hierarchy and the VM context. That means the old context and object refs are invalided and should not be touched again. Apparently the implement reported a calling result to the old context by invoke JS_SET_RVAL(cx, vp, JSVAL_VOID);
Still, this is not the real big problem. The big problem here is __restartVM left cached script object unchanged which is associated with the old script context. Maybe we should clean filename_script also when destroy a script context.
To think a way to restart entire cocos2d-x. I need to restart the director, the audio engine, the scripting VM.
I think I can restart the director not so gracefully. The Audio engine is piece of cake. Maybe I should just restart the VM and reset every relevant variables manually. And start everything from CCApplication::run.