diff --git a/src/tilecache.js b/src/tilecache.js index 6839e15a..2b7575a5 100644 --- a/src/tilecache.js +++ b/src/tilecache.js @@ -1132,6 +1132,24 @@ } } + /** + * Delete all data in the cache + * @param {boolean} withZombies + */ + clear(withZombies = true) { + for (let zombie in this._zombiesLoaded) { + this._zombiesLoaded[zombie].destroy(); + } + for (let tile in this._tilesLoaded) { + this._unloadTile(tile, true, undefined); + } + this._tilesLoaded = []; + this._zombiesLoaded = []; + this._zombiesLoadedCount = 0; + this._cachesLoaded = []; + this._cachesLoadedCount = 0; + } + /** * Returns reference to all tiles loaded by a particular * tiled image item diff --git a/src/viewer.js b/src/viewer.js index 4450158c..f3be8102 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -812,6 +812,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, THIS[ this.hash ].animating = false; this.world.removeAll(); + this.tileCache.clear(); this.imageLoader.clear(); /** diff --git a/src/webgldrawer.js b/src/webgldrawer.js index 624f3937..536c264d 100644 --- a/src/webgldrawer.js +++ b/src/webgldrawer.js @@ -374,14 +374,15 @@ // iterate over tiles and add data for each one to the buffers for(let tileIndex = 0; tileIndex < tilesToDraw.length; tileIndex++){ let tile = tilesToDraw[tileIndex].tile; - const textureInfo = this.getDataToDraw(tile); - if (!textureInfo) { - continue; - } - let indexInDrawArray = tileIndex % maxTextures; let numTilesToDraw = indexInDrawArray + 1; - this._getTileData(tile, tiledImage, textureInfo, overallMatrix, indexInDrawArray, texturePositionArray, textureDataArray, matrixArray, opacityArray); + const textureInfo = this.getDataToDraw(tile); + + if (textureInfo) { + this._getTileData(tile, tiledImage, textureInfo, overallMatrix, indexInDrawArray, texturePositionArray, textureDataArray, matrixArray, opacityArray); + } else { + // console.log('No tile info', tile); + } if( (numTilesToDraw === maxTextures) || (tileIndex === tilesToDraw.length - 1)){ // We've filled up the buffers: time to draw this set of tiles diff --git a/src/world.js b/src/world.js index a2836028..737b6760 100644 --- a/src/world.js +++ b/src/world.js @@ -270,6 +270,10 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W * @return {OpenSeadragon.Promise} */ requestTileInvalidateEvent: function(tilesToProcess, tStamp, restoreTiles = true, _allowTileUnloaded = false) { + if (!this.viewer.isOpen()) { + return $.Promise.resolve(); + } + const tileList = [], markedTiles = []; for (const tile of tilesToProcess) { @@ -372,7 +376,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W return eventTarget.raiseEventAwaiting('tile-invalidated', { tile: tile, tiledImage: tiledImage, - outdated: () => originalCache.__invStamp !== tStamp, + outdated: () => originalCache.__invStamp !== tStamp || (!tile.loaded && !tile.loading), getData: getWorkingCacheData, setData: setWorkingCacheData, resetData: () => { @@ -382,7 +386,7 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W } } }).then(_ => { - if (originalCache.__invStamp === tStamp) { + if (originalCache.__invStamp === tStamp && (tile.loaded || tile.loading)) { if (workingCache) { return workingCache.prepareForRendering(drawerId, supportedFormats, keepInternalCacheCopy).then(c => { if (c && originalCache.__invStamp === tStamp) { diff --git a/test/modules/formats.js b/test/modules/formats.js index 6b5c7fb6..bd851b92 100644 --- a/test/modules/formats.js +++ b/test/modules/formats.js @@ -29,7 +29,7 @@ }; var testOpen = function(tileSource, assert) { - var timeWatcher = Util.timeWatcher(assert, 7000); + const done = assert.async(); viewer = OpenSeadragon({ id: 'example', @@ -56,7 +56,7 @@ viewer.removeHandler('close', closeHandler); $('#example').empty(); assert.ok(true, 'Close event was sent'); - timeWatcher.done(); + done(); }; viewer.addHandler('open', openHandler); };