@@ -12,6 +12,8 @@ import {
1212import {
1313 DynoProgram ,
1414 DynoProgramTemplate ,
15+ DynoSampler2D ,
16+ type DynoType ,
1517 DynoUniform ,
1618 DynoVec2 ,
1719 DynoVec4 ,
@@ -241,12 +243,32 @@ export class PackedSplats {
241243 dispose ( ) {
242244 if ( this . target ) {
243245 this . target . dispose ( ) ;
246+ this . target . texture . source . data = null ;
244247 this . target = null ;
245248 }
246249 if ( this . source ) {
247250 this . source . dispose ( ) ;
251+ this . source . source . data = null ;
248252 this . source = null ;
249253 }
254+
255+ this . packedArray = null ;
256+
257+ for ( const key in this . extra ) {
258+ const dyno = this . extra [ key ] as DynoUniform <
259+ DynoType ,
260+ string ,
261+ THREE . Texture
262+ > ;
263+ if ( dyno instanceof DynoUniform ) {
264+ const texture = dyno . value ;
265+ if ( texture ?. isTexture ) {
266+ texture . dispose ( ) ;
267+ texture . source . data = null ;
268+ }
269+ }
270+ }
271+ this . extra = { } ;
250272 }
251273
252274 // Ensures that this.packedArray can fit numSplats Gsplats. If it's too small,
@@ -432,7 +454,9 @@ export class PackedSplats {
432454 if ( this . target && ( maxSplats ?? 1 ) <= this . maxSplats ) {
433455 return false ;
434456 }
435- this . dispose ( ) ;
457+ if ( this . target ) {
458+ this . target . dispose ( ) ;
459+ }
436460
437461 const textureSize = getTextureSize ( maxSplats ?? 1 ) ;
438462 const { width, height, depth } = textureSize ;
@@ -687,7 +711,7 @@ export class PackedSplats {
687711 static programTemplate : DynoProgramTemplate | null = null ;
688712
689713 // Cache for GsplatGenerator programs
690- static generatorProgram = new Map < GsplatGenerator , DynoProgram > ( ) ;
714+ static generatorProgram = new WeakMap < GsplatGenerator , DynoProgram > ( ) ;
691715
692716 // Static full-screen quad for pseudo-compute shader rendering
693717 static fullScreenQuad = new FullScreenQuad (
0 commit comments