@@ -479,9 +479,15 @@ export class SparkViewpoint {
479479 // Splat mapping has not changed, so reuse the existing sorted
480480 // geometry to show updates faster. We will still fire off
481481 // a re-sort if necessary. First release old accumulator.
482+ accumulator . refCount += 1 ;
482483 this . spark . releaseAccumulator ( this . display . accumulator ) ;
483484 this . display . accumulator = accumulator ;
485+ this . display . viewToWorld . copy ( this . viewToWorld ) ;
484486 displayed = true ;
487+
488+ if ( this . spark . viewpoint === this ) {
489+ this . spark . prepareViewpoint ( this ) ;
490+ }
485491 }
486492 }
487493
@@ -509,15 +515,12 @@ export class SparkViewpoint {
509515 }
510516
511517 if ( accumulator ) {
512- // Hold a reference to the accumulator so it isn't released
518+ // Hold a reference to the accumulator for sorting
513519 accumulator . refCount += 1 ;
514520 }
515521
516- if (
517- accumulator &&
518- this . pending ?. accumulator &&
519- this . pending . accumulator !== this . display ?. accumulator
520- ) {
522+ if ( this . pending ?. accumulator ) {
523+ // Release the reference of the pending accumulator
521524 this . spark . releaseAccumulator ( this . pending . accumulator ) ;
522525 }
523526 this . pending = { accumulator, viewToWorld : this . viewToWorld , displayed } ;
@@ -533,9 +536,10 @@ export class SparkViewpoint {
533536 }
534537
535538 const { viewToWorld, displayed } = this . pending ;
536- let accumulator = this . pending . accumulator ?? this . display ?. accumulator ;
539+ let accumulator = this . pending . accumulator ;
537540 if ( ! accumulator ) {
538- accumulator = this . spark . active ;
541+ // Hold a reference to the accumulator while sorting
542+ accumulator = this . display ?. accumulator ?? this . spark . active ;
539543 accumulator . refCount += 1 ;
540544 }
541545 this . pending = null ;
@@ -546,6 +550,10 @@ export class SparkViewpoint {
546550 this . sorting = { viewToWorld } ;
547551 await this . sortUpdate ( { accumulator, viewToWorld, displayed } ) ;
548552 this . sorting = null ;
553+
554+ // Release the reference to the accumulator
555+ this . spark . releaseAccumulator ( accumulator ) ;
556+
549557 // Continue in loop with any queued sort
550558 }
551559 }
@@ -668,13 +676,18 @@ export class SparkViewpoint {
668676 displayed ?: boolean ;
669677 } ) {
670678 if ( ! this . display ) {
679+ // Hold a reference to the accumulator while part of display
680+ accumulator . refCount += 1 ;
671681 this . display = {
672682 accumulator,
673683 viewToWorld,
674684 geometry : new SplatGeometry ( ordering , activeSplats ) ,
675685 } ;
676686 } else {
677687 if ( ! displayed && accumulator !== this . display . accumulator ) {
688+ // Hold a reference to the new accumulator being displayed
689+ accumulator . refCount += 1 ;
690+ // Release the reference to the previously displayed accumulator
678691 this . spark . releaseAccumulator ( this . display . accumulator ) ;
679692 this . display . accumulator = accumulator ;
680693 }
0 commit comments