mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-29 00:26:10 +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 ] = {
|
THIS[ this.hash ] = {
|
||||||
"fsBoundsDelta": new $.Point( 1, 1 ),
|
"fsBoundsDelta": new $.Point( 1, 1 ),
|
||||||
"prevContainerSize": null,
|
"prevContainerSize": null,
|
||||||
|
"updateRequestId": null,
|
||||||
"animating": false,
|
"animating": false,
|
||||||
"forceRedraw": false,
|
"forceRedraw": false,
|
||||||
"mouseInside": false,
|
"mouseInside": false,
|
||||||
@ -353,7 +354,11 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
|
|||||||
* @return {OpenSeadragon.Viewer} Chainable.
|
* @return {OpenSeadragon.Viewer} Chainable.
|
||||||
*/
|
*/
|
||||||
close: function ( ) {
|
close: function ( ) {
|
||||||
|
if ( THIS[ this.hash ].updateRequestId !== null ){
|
||||||
|
$.cancelAnimationFrame( THIS[ this.hash ].updateRequestId );
|
||||||
|
THIS[ this.hash ].updateRequestId = null;
|
||||||
|
}
|
||||||
|
|
||||||
if( this.drawer ){
|
if( this.drawer ){
|
||||||
this.drawer.clearOverlays();
|
this.drawer.clearOverlays();
|
||||||
}
|
}
|
||||||
@ -1064,7 +1069,7 @@ function openTileSource( viewer, source ) {
|
|||||||
|
|
||||||
THIS[ _this.hash ].animating = false;
|
THIS[ _this.hash ].animating = false;
|
||||||
THIS[ _this.hash ].forceRedraw = true;
|
THIS[ _this.hash ].forceRedraw = true;
|
||||||
scheduleUpdate( _this, updateMulti );
|
THIS[ _this.hash ].updateRequestId = scheduleUpdate( _this, updateMulti );
|
||||||
|
|
||||||
//Assuming you had programatically created a bunch of overlays
|
//Assuming you had programatically created a bunch of overlays
|
||||||
//and added them via configuration
|
//and added them via configuration
|
||||||
@ -1338,13 +1343,11 @@ function updateMulti( viewer ) {
|
|||||||
|
|
||||||
var beginTime;
|
var beginTime;
|
||||||
|
|
||||||
if ( !viewer.source ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
beginTime = +new Date();
|
beginTime = +new Date();
|
||||||
updateOnce( viewer );
|
updateOnce( viewer );
|
||||||
scheduleUpdate( viewer, arguments.callee, beginTime );
|
|
||||||
|
THIS[ viewer.hash ].updateRequestId = scheduleUpdate( viewer,
|
||||||
|
arguments.callee, beginTime );
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateOnce( viewer ) {
|
function updateOnce( viewer ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user