numenta/nupic.cerebro2 — pull request #67 by mrcslws (2014-10-21 02:21:40+00:00)
Title: Show an error message in UI when WebGL fails to initialize

Addresses #66.

Let me know if this fix isn't surgical enough. And feel free to nitpick.

Small design decisions:
- I didn't add new WebGL detection logic. That would require creating a dummy canvas, etc.
- The error message comes from near the point of failure, rather than assuming we know what went wrong in main.js.
- The failure is localized to the container that fails to get populated, rather than leaving the exception uncaught. This helps avoid the red herring error messages mentioned in the original issue.
- I didn't try to create a super-user-friendly experience. It just shows the error message in place of the canvas. Good enough for hackers.
- To avoid duplicated try/catch for each visualization, and to avoid hypothetical broken scenarios where one visualization succeeds and the other fails:
- I created a helper function (addVisualization) with success callbacks.
- I store an array of historyConsumers rather than having one var per consumer (formally visualization2D, visualization3D).
- I change the GUISync so that the master can be specified outside of the constructor, so that the main.js code doesn't trip over itself if one of the visualizations fails to create.