Skip to content

Commit

Permalink
Add a workaround to reload if webgl context is lost
Browse files Browse the repository at this point in the history
This is based on the suggestion from

WorldWideTelescope/wwt-webgl-engine#199 (comment)
  • Loading branch information
DougBurke committed Aug 2, 2022
1 parent 1c5d796 commit 20edbbb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions website/wwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -4001,6 +4001,29 @@ var wwt = (function () {
function isVersion20() { return isVersion("2.0"); }
function isVersion21() { return isVersion("2.1"); }

// See https://github.com/WorldWideTelescope/wwt-webgl-engine/issues/199
//
// Hopefully this can be removed quickly. It's not clear how prevalent
// this is (e.g. is it only firefox).
//
function trackWebGLcontext() {
trace("Setting the webglcontextlost handler");
const canvas = document.getElementById("WWTCanvas").children[0];
if (typeof canvas === "undefined") {
etrace("Unable to find canvas element in WWTCanvas");
return;
}

canvas.addEventListener("webglcontextlost", (e) => {
etrace("Web GL context has been lost");

const timeout = 5;
reportUpdateMessage("There was a problem with WebGL. Reloading the page.", timeout);

setTimeout(() => { window.location.reload(); }, timeout * 1000);
});
}

// Note that the WWT "control" panel will not be displayed until
// WWT is initalized, even though various elements of the panel are
// set up in initialize.
Expand Down Expand Up @@ -4271,6 +4294,7 @@ var wwt = (function () {
const wwt_si = wwtlib.WWTControl.initControl('WWTCanvas');
trace('...initialized wwtlib');

trackWebGLcontext();
addSetupBanner();

// Do we need to bother with the status?
Expand Down

0 comments on commit 20edbbb

Please sign in to comment.