@@ -141,7 +141,7 @@ export class NgtsAccumulativeShadows {
141141 this . pLM ( ) . configure ( this . planeRef ( ) . nativeElement ) ;
142142 } ) ;
143143
144- effect ( ( ) => {
144+ effect ( ( onCleanup ) => {
145145 const sceneInstanceState = getInstanceState ( this . store . scene ( ) ) ;
146146 if ( ! sceneInstanceState ) return ;
147147
@@ -153,7 +153,19 @@ export class NgtsAccumulativeShadows {
153153 // Reset internals, buffers, ...
154154 this . reset ( ) ;
155155 // Update lightmap
156- if ( ! this . temporal ( ) && this . frames ( ) !== Infinity ) this . update ( this . blend ( ) ) ;
156+
157+ // TODO: (chau) this is a hack. not sure why a timeout is needed here. if not PLM.update
158+ // is erroring out on some scenes.
159+ let timeout : ReturnType < typeof setTimeout > ;
160+
161+ if ( ! this . temporal ( ) && this . frames ( ) !== Infinity ) {
162+ const blend = this . blend ( ) ;
163+ timeout = setTimeout ( ( ) => this . update ( blend ) ) ;
164+ }
165+
166+ onCleanup ( ( ) => {
167+ if ( timeout ) clearTimeout ( timeout ) ;
168+ } ) ;
157169 } ) ;
158170
159171 injectBeforeRender ( ( ) => {
@@ -207,7 +219,7 @@ export class NgtsAccumulativeShadows {
207219 // Update the lightmap and the accumulative lights
208220 for ( let i = 0 ; i < frames ; i ++ ) {
209221 this . lightsMap . forEach ( ( lightUpdate ) => lightUpdate ( ) ) ;
210- this . pLM ( ) . update ( this . store . camera ( ) , this . blend ( ) ) ;
222+ this . pLM ( ) . update ( this . store . snapshot . camera , this . blend ( ) ) ;
211223 }
212224 // Switch lights off
213225 this . lightsRef ( ) . nativeElement . visible = false ;
0 commit comments