@@ -145,7 +145,9 @@ export class VolumeLayer extends Layer implements ChannelsEnabled {
145145
146146 public onDetached ( _context : IdetikContext ) : void {
147147 if ( ! this . chunkStoreView_ ) return ;
148- this . releaseAndRemoveVolumes ( this . currentVolumes_ . values ( ) ) ;
148+ for ( const volume of this . currentVolumes_ . values ( ) ) {
149+ this . releaseAndRemoveVolume ( volume ) ;
150+ }
149151 this . clearObjects ( ) ;
150152 this . chunkStoreView_ . dispose ( ) ;
151153 this . chunkStoreView_ = undefined ;
@@ -164,17 +166,16 @@ export class VolumeLayer extends Layer implements ChannelsEnabled {
164166 this . lastLoadedTime_ !== currentTime ||
165167 groupedChunks . size !== this . currentVolumes_ . size ||
166168 this . lastNumRenderedChannelChunks_ !== chunksToRender . length ;
167- this . lastNumRenderedChannelChunks_ = chunksToRender . length ;
168169 if ( ! needsUpdate ) return ;
169170
170- const volumesToRemove = Array . from ( this . currentVolumes_ . entries ( ) )
171- . filter ( ( [ key ] ) => ! groupedChunks . has ( key ) )
172- . map ( ( [ , volume ] ) => volume ) ;
173- this . releaseAndRemoveVolumes ( volumesToRemove ) ;
171+ for ( const [ key , volume ] of this . currentVolumes_ ) {
172+ if ( ! groupedChunks . has ( key ) ) {
173+ this . releaseAndRemoveVolume ( volume ) ;
174+ this . currentVolumes_ . delete ( key ) ;
175+ }
176+ }
174177
175- this . currentVolumes_ . clear ( ) ;
176178 this . clearObjects ( ) ;
177-
178179 for ( const [ key , chunks ] of groupedChunks ) {
179180 const volume = this . getOrCreateVolume ( key , chunks ) ;
180181 volume . wireframeEnabled = this . debugShowWireframes ;
@@ -183,6 +184,7 @@ export class VolumeLayer extends Layer implements ChannelsEnabled {
183184 }
184185
185186 this . lastLoadedTime_ = currentTime ;
187+ this . lastNumRenderedChannelChunks_ = chunksToRender . length ;
186188 if ( this . state !== "ready" ) this . setState ( "ready" ) ;
187189 }
188190
@@ -206,12 +208,10 @@ export class VolumeLayer extends Layer implements ChannelsEnabled {
206208 ] ) ;
207209 }
208210
209- private releaseAndRemoveVolumes ( volumes : Iterable < VolumeRenderable > ) {
210- for ( const volume of volumes ) {
211- volume . clearLoadedChannels ( ) ;
212- this . pool_ . release ( this . volumeToPoolKey_ . get ( volume ) ! , volume ) ;
213- this . volumeToPoolKey_ . delete ( volume ) ;
214- }
211+ private releaseAndRemoveVolume ( volume : VolumeRenderable ) {
212+ volume . clearLoadedChannels ( ) ;
213+ this . pool_ . release ( this . volumeToPoolKey_ . get ( volume ) ! , volume ) ;
214+ this . volumeToPoolKey_ . delete ( volume ) ;
215215 }
216216
217217 public update ( context ?: RenderContext ) {
0 commit comments