mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 06:36:11 +03:00
Fix timer leak after multiple Viewer.open() calls, take 2
Track the request ID of the outstanding animation frame and cancel it on Viewer.close(). Fixes #76.
This commit is contained in:
parent
23c20e3d5a
commit
8cb2714dae
@ -115,6 +115,7 @@ $.Viewer = function( options ) {
|
||||
THIS[ this.hash ] = {
|
||||
"fsBoundsDelta": new $.Point( 1, 1 ),
|
||||
"prevContainerSize": null,
|
||||
"updateRequestId": null,
|
||||
"animating": false,
|
||||
"forceRedraw": false,
|
||||
"mouseInside": false,
|
||||
@ -353,7 +354,11 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
|
||||
* @return {OpenSeadragon.Viewer} Chainable.
|
||||
*/
|
||||
close: function ( ) {
|
||||
|
||||
if ( THIS[ this.hash ].updateRequestId !== null ){
|
||||
$.cancelAnimationFrame( THIS[ this.hash ].updateRequestId );
|
||||
THIS[ this.hash ].updateRequestId = null;
|
||||
}
|
||||
|
||||
if( this.drawer ){
|
||||
this.drawer.clearOverlays();
|
||||
}
|
||||
@ -1064,7 +1069,7 @@ function openTileSource( viewer, source ) {
|
||||
|
||||
THIS[ _this.hash ].animating = false;
|
||||
THIS[ _this.hash ].forceRedraw = true;
|
||||
scheduleUpdate( _this, updateMulti );
|
||||
THIS[ _this.hash ].updateRequestId = scheduleUpdate( _this, updateMulti );
|
||||
|
||||
//Assuming you had programatically created a bunch of overlays
|
||||
//and added them via configuration
|
||||
@ -1338,13 +1343,11 @@ function updateMulti( viewer ) {
|
||||
|
||||
var beginTime;
|
||||
|
||||
if ( !viewer.source ) {
|
||||
return;
|
||||
}
|
||||
|
||||
beginTime = +new Date();
|
||||
updateOnce( viewer );
|
||||
scheduleUpdate( viewer, arguments.callee, beginTime );
|
||||
|
||||
THIS[ viewer.hash ].updateRequestId = scheduleUpdate( viewer,
|
||||
arguments.callee, beginTime );
|
||||
}
|
||||
|
||||
function updateOnce( viewer ) {
|
||||
|
Loading…
Reference in New Issue
Block a user