Restart game in case of error?

Restart game in case of error?
0.0 0



it’s possible to restart the game in case of an error on js-binding? I know that our games must be without errors, but sometimes you could have a division/0 or some nasty error, and the game gets “frozen” on devices.

I was trying to make something to restart the game in case of error, but doesn’t work. This is the code I tryed on my cocos2d-jsb.js file.

//Infinite loop of menu
var launch = function(director){
        director.runWithScene(new MenuScene);
    } catch(e) {



launch is only excuted once.
it’s not infinite loop.
in c++:
* while(1){
* mainLoop();
* }
in js, also jsb:
* begin()
* setinternal(mainLoop, 16); //perhaps 16ms
launch will excute once and goto scene.
then, crash will happened in mainloop, launch will not catch it.

also it is not recommended to use try catch in JS, as it is really slowly.


Could you post the js code?

I tryed with setInternal and its making a loop with lot of erros.




ok, setInterval makes the function “callback” to be called every time.

But this is not why I need. I need something to cach errors on my game (like try/catch) and restart the game in case of any error. I tryed with try/catch but doesn’t work for me. When something bad happens, the game hangs.