Merge pull request #2282 from RationAI/master

Ensure tile-loaded event completionCallback is called only once.
This commit is contained in:
Ian Gilman 2023-02-03 14:03:39 -08:00 committed by GitHub
commit 3cf3fb50b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1656,9 +1656,14 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
*/ */
_setTileLoaded: function(tile, data, cutoff, tileRequest) { _setTileLoaded: function(tile, data, cutoff, tileRequest) {
var increment = 0, var increment = 0,
eventFinished = false,
_this = this; _this = this;
function getCompletionCallback() { function getCompletionCallback() {
if (eventFinished) {
$.console.error("Event 'tile-loaded' argument getCompletionCallback must be called synchronously. " +
"Its return value should be called asynchronously.");
}
increment++; increment++;
return completionCallback; return completionCallback;
} }
@ -1700,6 +1705,8 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
* marked as entirely loaded when the callback has been called once for each * marked as entirely loaded when the callback has been called once for each
* call to getCompletionCallback. * call to getCompletionCallback.
*/ */
var fallbackCompletion = getCompletionCallback();
this.viewer.raiseEvent("tile-loaded", { this.viewer.raiseEvent("tile-loaded", {
tile: tile, tile: tile,
tiledImage: this, tiledImage: this,
@ -1711,8 +1718,9 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
data: data, data: data,
getCompletionCallback: getCompletionCallback getCompletionCallback: getCompletionCallback
}); });
eventFinished = true;
// In case the completion callback is never called, we at least force it once. // In case the completion callback is never called, we at least force it once.
getCompletionCallback()(); fallbackCompletion();
}, },
/** /**