From 02898cfc173e076b1153ebb954ec8f7dc8a611da Mon Sep 17 00:00:00 2001 From: Tom Date: Mon, 12 Feb 2024 18:05:33 -0500 Subject: [PATCH] clean up bound event handlers in webgldrawer.destroy --- src/webgldrawer.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/webgldrawer.js b/src/webgldrawer.js index e5b8f811..b747779e 100644 --- a/src/webgldrawer.js +++ b/src/webgldrawer.js @@ -93,8 +93,10 @@ this._backupCanvasDrawer = null; // Add listeners for events that require modifying the scene or camera - this.viewer.addHandler("tile-ready", ev => this._tileReadyHandler(ev)); - this.viewer.addHandler("image-unloaded", ev => this._imageUnloadedHandler(ev)); + this._boundToTileReady = ev => this._tileReadyHandler(ev); + this._boundToImageUnloaded = ev => this._imageUnloadedHandler(ev); + this.viewer.addHandler("tile-ready", this._boundToTileReady); + this.viewer.addHandler("image-unloaded", this._boundToImageUnloaded); // Reject listening for the tile-drawing and tile-drawn events, which this drawer does not fire this.viewer.rejectEventHandler("tile-drawn", "The WebGLDrawer does not raise the tile-drawn event"); @@ -155,6 +157,10 @@ ext.loseContext(); } + // unbind our event listeners from the viewer + this.viewer.removeHandler("tile-ready", this._boundToTileReady); + this.viewer.removeHandler("image-unloaded", this._boundToImageUnloaded); + // set our webgl context reference to null to enable garbage collection this._gl = null;