diff --git a/changelog.txt b/changelog.txt index ddb10df9..5e058c2c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -50,6 +50,7 @@ OPENSEADRAGON CHANGELOG * Viewport.setRotation now allows all rotation angles (#466) * Pinch rotate is now available (defaults to off) (#468) * Added option for home button to fill viewer (#474) +* Better handling of mid-update image loaded callbacks (#409) 1.1.1: diff --git a/src/imageLoader.js b/src/imageLoader.js index 1934051f..f1d5265d 100644 --- a/src/imageLoader.js +++ b/src/imageLoader.js @@ -133,7 +133,14 @@ $.ImageLoader.prototype = /** @lends OpenSeadragon.ImageLoader.prototype */{ else { this.jobQueue.push( newJob ); } + }, + /** + * Clear any unstarted image loading jobs from the queue. + * @method + */ + clear: function() { + this.jobQueue = []; } }; diff --git a/src/tiledimage.js b/src/tiledimage.js index c8ad9d93..cfe4a0b3 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -571,31 +571,40 @@ function loadTile( tiledImage, tile, time ) { } function onTileLoad( tiledImage, tile, time, image ) { - tile.loading = false; - - if ( tiledImage.midUpdate ) { - $.console.warn( "Tile load callback in middle of drawing routine." ); - return; - } else if ( !image ) { + if ( !image ) { $.console.log( "Tile %s failed to load: %s", tile, tile.url ); if( !tiledImage.debugMode ){ + tile.loading = false; tile.exists = false; return; } } else if ( time < tiledImage.lastResetTime ) { $.console.log( "Ignoring tile %s loaded before reset: %s", tile, tile.url ); + tile.loading = false; return; } - tile.loaded = true; - tile.image = image; + var finish = function() { + tile.loading = false; + tile.loaded = true; + tile.image = image; - var cutoff = Math.ceil( Math.log( tiledImage.source.getTileSize(tile.level) ) / Math.log( 2 ) ); - tiledImage._tileCache.cacheTile({ - tile: tile, - cutoff: cutoff, - tiledImage: tiledImage - }); + var cutoff = Math.ceil( Math.log( tiledImage.source.getTileSize(tile.level) ) / Math.log( 2 ) ); + tiledImage._tileCache.cacheTile({ + tile: tile, + cutoff: cutoff, + tiledImage: tiledImage + }); + }; + + // Check if we're mid-update; this can happen on IE8 because image load events for + // cached images happen immediately there + if ( !tiledImage.midUpdate ) { + finish(); + } else { + // Wait until after the update, in case caching unloads any tiles + window.setTimeout( finish, 1); + } tiledImage.updateAgain = true; }