Skip to content

Commit

Permalink
Repair error messages
Browse files Browse the repository at this point in the history
Some of the error message code has been broken for a bit. 1) Error
messages from a web socket load have not been clearing themselves
automatically when the error has been fixed, and 2) error messages from
the looper have not been displayed at all. This commit fixes both of
these regressions.
  • Loading branch information
sigvef committed Oct 28, 2017
1 parent 7bf5816 commit 34d7baa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 7 additions & 1 deletion nin/frontend/app/scripts/components/demoplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ class DemoPlayer extends React.Component {
// exit fullscreen
document.body.classList.remove('fullscreen');
}
this.props.demo.resize();
try {
this.props.demo.resize();
} catch(e) {
/* just ignoring any crashes here since they will be caught in the next
* render loop anyway, and we have a nicer error formatting setup over
* there. */
}
this.resizeOverlay();
}

Expand Down
3 changes: 2 additions & 1 deletion nin/frontend/app/scripts/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class Main extends React.Component<any, any> {
};

demo.music.setVolume(1 - this.state.mute);
demo.registerMainComponent(this);

commands.on('playSplashScreen', () => {
this.startupSound = new Audio();
Expand Down Expand Up @@ -185,7 +186,7 @@ export default class Main extends React.Component<any, any> {
e.name = event.name;

const globalJSErrors = (Object as any).assign({}, this.state.globalJSErrors);
globalJSErrors[event.type] = e;
globalJSErrors[event.name] = e;
this.setState({globalJSErrors});
}
});
Expand Down
17 changes: 14 additions & 3 deletions nin/frontend/app/scripts/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const demo = bootstrap({

window.demo = demo;

demo.globalJSErrors = demo.globalJSErrors || {};
var originalLoop = demo.looper.loop;
var forcedPause = false;
const stats = [];
Expand All @@ -31,6 +30,12 @@ commands.on('toggleStats', () => {
}
});

let main;

demo.registerMainComponent = function(mainComponent) {
main = mainComponent;
};


demo.looper.loop = function() {
try {
Expand All @@ -47,10 +52,16 @@ demo.looper.loop = function() {
forcedPause = false;
}

delete demo.globalJSErrors.looper;
if(main.state.globalJSErrors.looper) {
const globalJSErrors = Object.assign({}, main.state.globalJSErrors);
delete globalJSErrors.looper;
main.setState({globalJSErrors});
}
} catch(e) {
e.context = "Error during looping of demo";
demo.globalJSErrors.looper = e;
const globalJSErrors = Object.assign({}, main.state.globalJSErrors);
globalJSErrors.looper = e;
main.setState({globalJSErrors});

demo.looper.deltaTime += demo.looper.frameLength;
demo.looper.currentFrame -= 1;
Expand Down

0 comments on commit 34d7baa

Please sign in to comment.