Skip to content

Commit

Permalink
Add disposal support
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson committed Jul 6, 2024
1 parent 78470bb commit 04f093d
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions example/src/plugins/overlays/TextureOverlayPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class TextureOverlayPlugin {

};

tiles.addEventListener( 'dispose-model', ( { tile } ) => {
this._disposeModelCallback = ( { tile } ) => {

const caches = this.caches;
for ( const key in caches ) {
Expand All @@ -214,19 +214,17 @@ export class TextureOverlayPlugin {

}

} );
};

tiles.addEventListener( 'load-model', ( { tile, scene } ) => {
this._assignTexturesCallback = ( { tile, scene } ) => {

this.assignCallback( scene, tile, this );

} );

tiles.addEventListener( 'layer-textures-change', ( { tile, scene } ) => {

this.assignCallback( scene, tile, this );
};

} );
tiles.addEventListener( 'dispose-model', this._disposeModelCallback );
tiles.addEventListener( 'load-model', this._assignTexturesCallback );
tiles.addEventListener( 'layer-textures-change', this._assignTexturesCallback );

}

Expand All @@ -249,6 +247,21 @@ export class TextureOverlayPlugin {

}

dispose() {

const { caches, tiles } = this;
Object.keys( caches ).forEach( key => {

this.unregisterLayer( key );

} );

tiles.removeEventListener( 'dispose-model', this._disposeModelCallback );
tiles.removeEventListener( 'load-model', this._assignTexturesCallback );
tiles.removeEventListener( 'layer-textures-change', this._assignTexturesCallback );

}

// public functions
getTileKey( tile ) {

Expand Down

0 comments on commit 04f093d

Please sign in to comment.