From eb50628da1852afa5a1586f88bcd1e01a3e63468 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 25 Mar 2022 20:41:20 -0400 Subject: [PATCH] Stop loading panorama is viewer is destroyed (fixed #1084). If the viewer is destroyed, we now try to abort loading equirectangular and cube map panoramas. This appears to work in Chrome but not in Firefox. No attempt is made to stop loading multires images, since that process is more complicated. --- src/js/pannellum.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/js/pannellum.js b/src/js/pannellum.js index 1657e61..b80af51 100644 --- a/src/js/pannellum.js +++ b/src/js/pannellum.js @@ -71,6 +71,7 @@ var config, eps = 1e-6, resizeObserver, hotspotsCreated = false, + xhr, destroyed = false; var defaultConfig = { @@ -411,7 +412,7 @@ function init() { onImageLoad(); }; - var xhr = new XMLHttpRequest(); + xhr = new XMLHttpRequest(); xhr.onloadend = function() { if (xhr.status != 200) { // Display error if image can't be loaded @@ -419,6 +420,7 @@ function init() { a.href = p; a.textContent = a.href; anError(config.strings.fileAccessError.replace('%s', a.outerHTML)); + return; } var img = this.response; parseGPanoXMP(img, p); @@ -3347,6 +3349,12 @@ this.destroy = function() { destroyed = true; clearTimeout(autoRotateStart); + if (xhr) + xhr.abort(); + if (Array.isArray(panoImage)) { + for (var i = 0; i < 6; i++) + panoImage[i].src = ''; + } if (renderer) renderer.destroy(); if (listenersAdded) {