@@ -187,7 +187,7 @@ public virtual void addListener(ImageListener listener, ImageErrorListener onErr
187
187
new UIWidgetsErrorDetails (
188
188
exception : ex ,
189
189
library : "image resource service" ,
190
- context : "by a synchronously-called image error listener"
190
+ context : "when reporting an error to an image listener"
191
191
)
192
192
) ;
193
193
}
@@ -298,9 +298,6 @@ public MultiFrameImageStreamCompleter(
298
298
this . _scale = scale ;
299
299
this . _informationCollector = informationCollector ;
300
300
301
- this . _framesEmitted = 0 ;
302
- this . _timer = null ;
303
-
304
301
codec . Then ( ( Action < Codec > ) this . _handleCodecReady , ex => {
305
302
this . reportError (
306
303
context : "resolving an image codec" ,
@@ -318,17 +315,22 @@ public MultiFrameImageStreamCompleter(
318
315
FrameInfo _nextFrame ;
319
316
TimeSpan ? _shownTimestamp ;
320
317
TimeSpan ? _frameDuration ;
321
- int _framesEmitted ;
318
+ int _framesEmitted = 0 ;
322
319
Timer _timer ;
323
320
321
+ bool _frameCallbackScheduled = false ;
322
+
324
323
void _handleCodecReady ( Codec codec ) {
325
324
this . _codec = codec ;
326
325
D . assert ( this . _codec != null ) ;
327
326
328
- this . _decodeNextFrameAndSchedule ( ) ;
327
+ if ( this . hasListeners ) {
328
+ this . _decodeNextFrameAndSchedule ( ) ;
329
+ }
329
330
}
330
331
331
332
void _handleAppFrame ( TimeSpan timestamp ) {
333
+ this . _frameCallbackScheduled = false ;
332
334
if ( ! this . hasListeners ) {
333
335
return ;
334
336
}
@@ -349,8 +351,7 @@ void _handleAppFrame(TimeSpan timestamp) {
349
351
350
352
TimeSpan delay = this . _frameDuration . Value - ( timestamp - this . _shownTimestamp . Value ) ;
351
353
delay = new TimeSpan ( ( long ) ( delay . Ticks * SchedulerBinding . instance . timeDilation ) ) ;
352
- this . _timer = Window . instance . run ( delay ,
353
- ( ) => { SchedulerBinding . instance . scheduleFrameCallback ( this . _handleAppFrame ) ; } ) ;
354
+ this . _timer = Window . instance . run ( delay , this . _scheduleAppFrame ) ;
354
355
}
355
356
356
357
bool _isFirstFrame ( ) {
@@ -371,6 +372,15 @@ void _decodeNextFrameAndSchedule() {
371
372
return ;
372
373
}
373
374
375
+ this . _scheduleAppFrame ( ) ;
376
+ }
377
+
378
+ void _scheduleAppFrame ( ) {
379
+ if ( this . _frameCallbackScheduled ) {
380
+ return ;
381
+ }
382
+
383
+ this . _frameCallbackScheduled = true ;
374
384
SchedulerBinding . instance . scheduleFrameCallback ( this . _handleAppFrame ) ;
375
385
}
376
386
0 commit comments