excaliburjs / Excalibur

🎮 Your friendly TypeScript 2D game engine for the web 🗡️
https://excaliburjs.com
BSD 2-Clause "Simplified" License
1.83k stars 192 forks source link

Catch global (fatal) errors to aid in debugging #381

Closed kamranayub closed 9 years ago

kamranayub commented 9 years ago

Exascerbated by mobile, update loop errors can cause crashing and are hard to debug. Can we figure out a way to intelligently catch errors in update loop and break/stop the game execution so it doesn't wedge browsers?

mainloop() {

  try {
    engine.update(delta);
  } catch (e) {
    // update loop error, catch and rethrow safely with debugging info
   cancelRequestAnimationFrame(mainloop);
  }
}
eonarheim commented 9 years ago

@kamranayub Agreed, this is an important feature. It is really frustrating to debug when the mainloop keeps firing.

eonarheim commented 9 years ago

@kamranayub Should we also add an option to toast a friendly message to the user if the game crashes hard? Like "Oops, something went wrong. Please contact your friendly neighborhood game developer"?

alanag13 commented 9 years ago

@eonarheim if such a message exists it should be configurable.

eonarheim commented 9 years ago

@alanag13 Agreed

kamranayub commented 9 years ago

I think it should just be an action that you can override.

engine.onFatalException = (ex) => { ex.Logger.getInstance().fatal(ex); };

try {
 ...
} catch (ex) {
  this.onFatalException(ex);
}
eonarheim commented 9 years ago

@alanag13 @kamranayub I like having a event handler for this.

Should we expose something like this too?

engine.on('fatalexception', ()=>{...})
kamranayub commented 9 years ago

Thought of that, figured one of the fatal errors could be with the event dispatcher. This way it's very minimal, with no infrastructure to handle fatal exceptions.

On Thu, Apr 2, 2015 at 7:57 PM Erik Onarheim notifications@github.com wrote:

@alanag13 https://github.com/alanag13 @kamranayub https://github.com/kamranayub I like having a event handler for this.

Should we expose something like this too?

engine.on('fatalexception', ()=>{...})

— Reply to this email directly or view it on GitHub https://github.com/excaliburjs/Excalibur/issues/381#issuecomment-88991818 .

eonarheim commented 9 years ago

That is a good point... let's just do the engine.onFatalException