From 20edbbbea60f2503f8ead08d27e540b76152752c Mon Sep 17 00:00:00 2001 From: Doug Burke Date: Tue, 2 Aug 2022 13:49:31 -0400 Subject: [PATCH] Add a workaround to reload if webgl context is lost This is based on the suggestion from https://github.com/WorldWideTelescope/wwt-webgl-engine/issues/199#issuecomment-1202709323 --- website/wwt.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/website/wwt.js b/website/wwt.js index a9b7d98..95c5e9a 100644 --- a/website/wwt.js +++ b/website/wwt.js @@ -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. @@ -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?