You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Change causing a crash while image decoding #164944
UnknownError: Null check operator used on a null value
at MultiFrameImageStreamCompleter._decodeNextFrameAndSchedule (image_stream.dart:1133)
Sometimes the code line is 1111 depending on the version of flutter I have. That points to the _codec vairable being null checked before being disposed here:
The codec_ variable is null checked a few lines above that. Furthermore that line is inside a block that acceess a property on codec. Seems like that would crash first?
I believe the _emitFrame call here must have a side effect that occasionally causes the _codec to be disposed - maybe the receiver of the frame disposes the codec for some reason in certain circumstances? I could conceive of that calling some callback in client code which in-turn calls dispose on the image stream or something.
Yeah that makes sense. THe listeners run immediately so one could decide to dispose the image. So just changing the final !.dispose to a ?dispose should be safe.
_emitFrame calls setImage, which invokes listener onImage callbacks. The callback may remove the last listener, resulting in a call to _maybeDispose which clears the _codec.
So adding the _codec null check after the _emitFrame call would solve this. I'll create a PR.
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.
Activity
jonahwilliams commentedon Mar 10, 2025
The codec_ variable is null checked a few lines above that. Furthermore that line is inside a block that acceess a property on codec. Seems like that would crash first?
flutter/packages/flutter/lib/src/painting/image_stream.dart
Lines 1091 to 1111 in b2a4a05
apwilson commentedon Mar 10, 2025
I believe the _emitFrame call here must have a side effect that occasionally causes the _codec to be disposed - maybe the receiver of the frame disposes the codec for some reason in certain circumstances? I could conceive of that calling some callback in client code which in-turn calls dispose on the image stream or something.
flutter/packages/flutter/lib/src/painting/image_stream.dart
Line 1105 in b2a4a05
It's not if it can happen. It definitely can happening - it's happening now.
The code should protect itself by using a ? instead of a ! or check for null first before attempting to dispose.
Note also I see it doing this null check on _codec in two places so we probably want to protect that second location too.
jonahwilliams commentedon Mar 10, 2025
Yeah that makes sense. THe listeners run immediately so one could decide to dispose the image. So just changing the final
!.disposeto a?disposeshould be safe.jason-simmons commentedon Mar 11, 2025
#164537 has a way to reproduce this in Wonderous.
Captured a stack trace from Wonderous:
_emitFramecallssetImage, which invokes listeneronImagecallbacks. The callback may remove the last listener, resulting in a call to_maybeDisposewhich clears the_codec.So adding the
_codecnull check after the_emitFramecall would solve this. I'll create a PR.Check for a null codec in MultiFrameImageStreamCompleter after callin…
Check for a null codec in MultiFrameImageStreamCompleter after callin…
github-actions commentedon Mar 26, 2025
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 -vand a minimal reproduction of the issue.Check for a null codec in MultiFrameImageStreamCompleter after callin…