Browse Source

Fix DOM leaks.

pull/72/head
Matthew Petroff 9 years ago
parent
commit
6d60b961ba
2 changed files with 14 additions and 3 deletions
  1. +7
    -0
      src/js/libpannellum.js
  2. +7
    -3
      src/js/pannellum.js

+ 7
- 0
src/js/libpannellum.js View File

@@ -86,6 +86,7 @@ function Renderer(container, image, imageType, video) {
var loaded = 0; var loaded = 0;
var world = this.world; var world = this.world;
var container = this.container; var container = this.container;
var renderer = this;
var onLoad = function() { var onLoad = function() {
// Draw image on canvas // Draw image on canvas
var faceCanvas = document.createElement('canvas'); var faceCanvas = document.createElement('canvas');
@@ -147,6 +148,7 @@ function Renderer(container, image, imageType, video) {
if (loaded == 6) { if (loaded == 6) {
fallbackImgSize = this.width; fallbackImgSize = this.width;
container.appendChild(world); container.appendChild(world);
renderer.image = null;
callback(); callback();
} }
}; };
@@ -286,9 +288,14 @@ function Renderer(container, image, imageType, video) {
gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.image[5]); gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.image[5]);
gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.image[0]); gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.image[0]);
gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.image[2]); gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.image[2]);
this.image = undefined;
} else { } else {
// Upload image to the texture // Upload image to the texture
gl.texImage2D(glBindType, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.image); gl.texImage2D(glBindType, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.image);
if (this.video !== true) {
// Allow memory to be freed
this.image = undefined;
}
} }


// Set parameters for rendering any size // Set parameters for rendering any size


+ 7
- 3
src/js/pannellum.js View File

@@ -215,6 +215,7 @@ function init() {
function onImageLoad() { function onImageLoad() {
renderer = new libpannellum.renderer(renderContainer, panoImage, config.type, config.video); renderer = new libpannellum.renderer(renderContainer, panoImage, config.type, config.video);
panoImage = undefined;
// Only add event listeners once // Only add event listeners once
if (!listenersAdded) { if (!listenersAdded) {
@@ -948,6 +949,7 @@ function renderInitCallback() {
// Remove image // Remove image
setTimeout(function() { setTimeout(function() {
renderContainer.removeChild(oldRenderer.fadeImg); renderContainer.removeChild(oldRenderer.fadeImg);
oldRenderer = undefined;
}, config.sceneFadeDuration); }, config.sceneFadeDuration);
} }
} }
@@ -1046,15 +1048,17 @@ function createHotSpots() {


function destroyHotSpots() { function destroyHotSpots() {
if (config.hotSpots) { if (config.hotSpots) {
config.hotSpots.forEach(function(hs) {
var current = hs.div;
for (var i = 0; i < config.hotSpots.length; i++) {
var current = config.hotSpots[i].div;
while(current.parentNode != renderContainer) { while(current.parentNode != renderContainer) {
current = current.parentNode; current = current.parentNode;
} }
renderContainer.removeChild(current); renderContainer.removeChild(current);
});
config.hotSpots[i].div = null;
}
} }
hotspotsCreated = false; hotspotsCreated = false;
config.hotSpots = undefined;
} }


function renderHotSpots() { function renderHotSpots() {


Loading…
Cancel
Save