From 947109718cb9c6c317da1dfa16ed5550584230de Mon Sep 17 00:00:00 2001 From: Aiosa Date: Sat, 28 Jan 2023 08:42:07 +0100 Subject: [PATCH] Ensure tile-loaded event completionCallback is called only once. Check when context2D used after cache creation. --- src/tiledimage.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index 928e135d..8a062c92 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -1655,17 +1655,17 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag * @param {XMLHttpRequest|undefined} tileRequest */ _setTileLoaded: function(tile, data, cutoff, tileRequest) { - var increment = 0, + var stopper = 1, + cached = false, _this = this; function getCompletionCallback() { - increment++; return completionCallback; } function completionCallback() { - increment--; - if (increment === 0) { + stopper--; + if (stopper > 0) { tile.loading = false; tile.loaded = true; tile.hasTransparency = _this.source.hasTransparency( @@ -1678,8 +1678,13 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag cutoff: cutoff, tiledImage: _this }); + cached = true; } _this._needsDraw = true; + } else if (tile.context2D && cached) { + $.console.error("The tile has been cached, yet tile.context2D was set afterwards." + + " The cache is orphaned now. To avoid this, increase the priority of 'tile-loaded' event " + + "attaching context2D property."); } }