@@ -141,7 +141,7 @@ export class NgtsAccumulativeShadows {
141
141
this . pLM ( ) . configure ( this . planeRef ( ) . nativeElement ) ;
142
142
} ) ;
143
143
144
- effect ( ( ) => {
144
+ effect ( ( onCleanup ) => {
145
145
const sceneInstanceState = getInstanceState ( this . store . scene ( ) ) ;
146
146
if ( ! sceneInstanceState ) return ;
147
147
@@ -153,7 +153,19 @@ export class NgtsAccumulativeShadows {
153
153
// Reset internals, buffers, ...
154
154
this . reset ( ) ;
155
155
// 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
+ } ) ;
157
169
} ) ;
158
170
159
171
injectBeforeRender ( ( ) => {
@@ -207,7 +219,7 @@ export class NgtsAccumulativeShadows {
207
219
// Update the lightmap and the accumulative lights
208
220
for ( let i = 0 ; i < frames ; i ++ ) {
209
221
this . lightsMap . forEach ( ( lightUpdate ) => lightUpdate ( ) ) ;
210
- this . pLM ( ) . update ( this . store . camera ( ) , this . blend ( ) ) ;
222
+ this . pLM ( ) . update ( this . store . snapshot . camera , this . blend ( ) ) ;
211
223
}
212
224
// Switch lights off
213
225
this . lightsRef ( ) . nativeElement . visible = false ;
0 commit comments