Skip to content

MultiFrameImageStreamCompleter null dereference #30340

Description

@amirh

Got reports from the wild with the following stack trace:

2019-04-01 20:27:21.453 8085-8351/com.example.myapp I/flutter: ══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
2019-04-01 20:27:21.474 8085-8351/com.example.myapp I/flutter: The following NoSuchMethodError was thrown during a scheduler callback:
2019-04-01 20:27:21.475 8085-8351/com.example.myapp I/flutter: The getter 'image' was called on null.
2019-04-01 20:27:21.475 8085-8351/com.example.myapp I/flutter: Receiver: null
2019-04-01 20:27:21.475 8085-8351/com.example.myapp I/flutter: Tried calling: image
2019-04-01 20:27:21.475 8085-8351/com.example.myapp I/flutter: When the exception was thrown, this was the stack:
2019-04-01 20:27:21.492 8085-8351/com.example.myapp I/flutter: #0      Object.noSuchMethod (dart:core/runtime/lib/object_patch.dart:50:5)
2019-04-01 20:27:21.493 8085-8351/com.example.myapp I/flutter: #1      MultiFrameImageStreamCompleter._handleAppFrame (package:flutter/src/painting/image_stream.dart:548:46)
2019-04-01 20:27:21.493 8085-8351/com.example.myapp I/flutter: #2      __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1012:15)
2019-04-01 20:27:21.493 8085-8351/com.example.myapp I/flutter: #3      __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding.handleBeginFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:928:11)
2019-04-01 20:27:21.493 8085-8351/com.example.myapp I/flutter: #4      __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.forEach (dart:collection/runtime/lib/compact_hash.dart:367:8)
2019-04-01 20:27:21.493 8085-8351/com.example.myapp I/flutter: #5      __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding.handleBeginFrame (package:flutter/src/scheduler/binding.dart:926:17)
2019-04-01 20:27:21.493 8085-8351/com.example.myapp I/flutter: #6      __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding._handleBeginFrame (package:flutter/src/scheduler/binding.dart:856:5)
2019-04-01 20:27:21.493 8085-8351/com.example.myapp I/flutter: #10     _invoke1 (dart:ui/hooks.dart:233:10)
2019-04-01 20:27:21.493 8085-8351/com.example.myapp I/flutter: #11     _beginFrame (dart:ui/hooks.dart:172:3)
2019-04-01 20:27:21.493 8085-8351/com.example.myapp I/flutter: (elided 3 frames from package dart:async)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: This exception was thrown in the context of a scheduler callback. When the scheduler callback was
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: _registered_ (as opposed to when the exception was thrown), this was the stack:
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: #0      new _FrameCallbackEntry.<anonymous closure> (package:flutter/src/scheduler/binding.dart:112:33)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: #1      new _FrameCallbackEntry (package:flutter/src/scheduler/binding.dart:115:6)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: #2      __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding.scheduleFrameCallback (package:flutter/src/scheduler/binding.dart:448:49)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: #3      MultiFrameImageStreamCompleter._decodeNextFrameAndSchedule (package:flutter/src/painting/image_stream.dart:592:31)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: <asynchronous suspension>
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: #4      MultiFrameImageStreamCompleter._handleAppFrame (package:flutter/src/painting/image_stream.dart:554:9)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: #5      __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1012:15)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: #6      __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding.handleBeginFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:928:11)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: #7      __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.forEach (dart:collection/runtime/lib/compact_hash.dart:367:8)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: #8      __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding.handleBeginFrame (package:flutter/src/scheduler/binding.dart:926:17)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: #9      __DriverBinding&BindingBase&ServicesBinding&SchedulerBinding._handleBeginFrame (package:flutter/src/scheduler/binding.dart:856:5)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: #13     _invoke1 (dart:ui/hooks.dart:233:10)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: #14     _beginFrame (dart:ui/hooks.dart:172:3)
2019-04-01 20:27:21.505 8085-8351/com.example.myapp I/flutter: (elided 3 frames from package dart:async)

After some analysis of the code I see how this can happen if _handleAppFrame is added multiple times as a frame callback. 2 ways in which this can happen:

Scenario 1

  1. A GIF frame is decoded and a Flutter frame is executed before it's time to show the next GIF frame.
  2. The timer that's waiting for enough time to elapse is invoked, and schedules a callback for the next Flutter frame(here).
  3. Before the next Flutter frame is executed, MultiFrameImageStreamCompleter#removeListener is called followed by ``MultiFrameImageStreamCompleter#addListenerthat is invoking_decodeNextFrameAndSchedule` which is adding `_handleAppFrame` again as a next frame callback.

Scenario 2
removeListener and addListener are called multiple times in succession, every call to addListener can result in another registration of _handleAppFrame to the next Flutter frame callbacks list.

Activity

  1. added this to the May 2019 milestone on Apr 1, 2019
  2. self-assigned this
    on Apr 1, 2019
  3. github-actions commented on Aug 30, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  4. locked as resolved and limited conversation to collaborators on Aug 30, 2021
  5. added a commit that references this issue on Oct 8, 2026
    ea4ba77
  6. added a commit that references this issue on Oct 29, 2026
    c8d7ceb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: crashStack traces logged to the consolecustomer: dream (g3)frameworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions