Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a workaround to reload if webgl context is lost #83

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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