brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.17k stars 263 forks source link

Unhandled Exception: LateInitializationError on PngEncoder()..isAnimated = true.addFrame() #294

Closed ghost closed 3 years ago

ghost commented 3 years ago
Launching lib\main.dart on FIG LX1 in debug mode...
lib\main.dart:1
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:53001/mRnZc_Ezr-I=/ws
D/AwareBitmapCacher(11693): handleInit switch not opened pid=11693
Reloaded 2 of 1065 libraries in 1,502ms.
V/AudioManager(11693): playSoundEffect   effectType: 0
V/AudioManager(11693): querySoundEffectsEnabled...
E/flutter (11693): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: LateInitializationError: Field '_frames@702470414' has not been initialized.
E/flutter (11693): #0      PngEncoder._frames (package:image/src/formats/png_encoder.dart)
package:image/…/formats/png_encoder.dart:1
E/flutter (11693): #1      PngEncoder._writeAnimationControlChunk
package:image/…/formats/png_encoder.dart:124
E/flutter (11693): #2      PngEncoder.addFrame
package:image/…/formats/png_encoder.dart:35
E/flutter (11693): #3      PainterPageState.build.<anonymous closure>
package:gif_maker/painter.dart:43
E/flutter (11693): #4      _WidgetRecorderState._getSnapshot
package:widget_recorder/widget_recorder.dart:100
E/flutter (11693): <asynchronous suspension>
E/flutter (11693): #5      WidgetRecorderPeriodicController._takeSnapshot
package:widget_recorder/src/widget_recorder_periodic_controller.dart:55
E/flutter (11693): <asynchronous suspension>
E/flutter (11693):
Exited (1)
brendan-duncan commented 3 years ago

Thanks for catching this, I just pushed a fix and will update the version.

Are you doing something specific calling addFrame directly instead of encodeImage or encodeAnimation? If you're adding multiple frames and not using encodeAnimation, you'll want to set pngEcoder.isAnimated = true prior to calling pngEncoder.addFrame(), so that it knows to add the animation control chunk to the PNG data. And don't forget to call pngEncoder.finish() after you're done calling addFrame, so it writes the end data chunk.