From 68f0ed8901dcd3dab6a8416398feb0bb2d5e1c17 Mon Sep 17 00:00:00 2001 From: Aiosa <469130@mail.muni.cz> Date: Mon, 21 Oct 2024 09:00:24 +0200 Subject: [PATCH] Do not spit out warns on invalid tile unload (preemtive working cache deletion), do not ignore working cache even if __restore=true. --- src/tile.js | 9 +++++---- src/tilecache.js | 15 +++++++++------ test/demo/filtering-plugin/index.html | 5 ----- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/tile.js b/src/tile.js index 55253881..5a9c65dc 100644 --- a/src/tile.js +++ b/src/tile.js @@ -539,7 +539,7 @@ $.Tile.prototype = { */ setData: function(value, type) { if (!this.tiledImage) { - return null; //async context can access the tile outside its lifetime + return Promise.resolve(); //async context can access the tile outside its lifetime } let cache = this.getCache(this._wcKey); @@ -594,7 +594,8 @@ $.Tile.prototype = { //TODO IMPLEMENT LOCKING AND IGNORE PIPELINE OUT OF THESE CALLS // Now, if working cache exists, we set main cache to the working cache, since it has been updated - const cache = !requestedRestore && this.getCache(this._wcKey); + // if restore() was called last, then working cache was deleted (does not exist) + const cache = this.getCache(this._wcKey); if (cache) { let newCacheKey = this.cacheKey === this.originalCacheKey ? "mod://" + this.originalCacheKey : this.cacheKey; this.tiledImage._tileCache.consumeCache({ @@ -745,7 +746,7 @@ $.Tile.prototype = { removeCache: function(key, freeIfUnused = true) { if (!this._caches[key]) { // try to erase anyway in case the cache got stuck in memory - this.tiledImage._tileCache.unloadCacheForTile(this, key, freeIfUnused); + this.tiledImage._tileCache.unloadCacheForTile(this, key, freeIfUnused, true); return; } @@ -771,7 +772,7 @@ $.Tile.prototype = { return; } } - if (this.tiledImage._tileCache.unloadCacheForTile(this, key, freeIfUnused)) { + if (this.tiledImage._tileCache.unloadCacheForTile(this, key, freeIfUnused, false)) { //if we managed to free tile from record, we are sure we decreased cache count delete this._caches[key]; } diff --git a/src/tilecache.js b/src/tilecache.js index d4b4d74c..79ae43b9 100644 --- a/src/tilecache.js +++ b/src/tilecache.js @@ -186,8 +186,8 @@ let internalCache = this[DRAWER_INTERNAL_CACHE]; internalCache = internalCache && internalCache[drawer.getId()]; if (keepInternalCopy && !internalCache) { - $.console.warn("Attempt to render tile that is not prepared with drawer requesting " + - "internal cache! This might introduce artifacts."); + $.console.warn("Attempt to render tile cache %s that is not prepared with drawer requesting " + + "internal cache! This might introduce artifacts.", this); this.prepareForRendering(drawer.getId(), supportedTypes, keepInternalCopy) .then(() => this._triggerNeedsDraw()); @@ -207,8 +207,8 @@ } if (!supportedTypes.includes(internalCache.type)) { - $.console.warn("Attempt to render tile that is not prepared for current drawer supported format: " + - "the preparation should've happened after tile processing has finished."); + $.console.warn("Attempt to render tile cache %s that is not prepared for current drawer " + + "supported format: the preparation should've happened after tile processing has finished.", this); internalCache.transformTo(supportedTypes.length > 1 ? supportedTypes : supportedTypes[0]) .then(() => this._triggerNeedsDraw()); @@ -1096,9 +1096,10 @@ * @param {OpenSeadragon.Tile} tile * @param {string} key cache key * @param {boolean} destroy if true, empty cache is destroyed, else left as a zombie + * @param {boolean} okIfNotExists sometimes we call destruction just to make sure, if true do not report as error * @private */ - unloadCacheForTile(tile, key, destroy) { + unloadCacheForTile(tile, key, destroy, okIfNotExists) { const cacheRecord = this._cachesLoaded[key]; //unload record only if relevant - the tile exists in the record if (cacheRecord) { @@ -1122,7 +1123,9 @@ "does not belong to! This could mean a bug in the cache system."); return false; } - $.console.warn("[TileCache.unloadCacheForTile] Attempting to delete missing cache!"); + if (!okIfNotExists) { + $.console.warn("[TileCache.unloadCacheForTile] Attempting to delete missing cache!"); + } return false; } diff --git a/test/demo/filtering-plugin/index.html b/test/demo/filtering-plugin/index.html index 1ae432c0..5c3f3b68 100644 --- a/test/demo/filtering-plugin/index.html +++ b/test/demo/filtering-plugin/index.html @@ -79,10 +79,5 @@ - - - -