Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

works in debug but throws Unhandled in release build #16

Open
sidetraxaudio opened this issue Apr 4, 2021 · 4 comments
Open

works in debug but throws Unhandled in release build #16

sidetraxaudio opened this issue Apr 4, 2021 · 4 comments

Comments

@sidetraxaudio
Copy link

Nice work - much appreciated however..
Compiling in release mode throws this:
Unhandled Exception: LateInitializationError: Local 'result' has not been initialized.

it seems to be related to the following line in builders/widget.dart
WidgetsBinding.instance!.addPostFrameCallback(_captureImage);

Symptom: perfect in debug, blank screen in release
Fixing it is beyond my skill as I'm just learning.

E/flutter (18180): #2 _PageTurnWidgetState._captureImage (package:ssv1/book_screen/builders/widget.dart:40)
E/flutter (18180): #3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144)
E/flutter (18180): #4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1090)
E/flutter (18180): #5 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:998)
E/flutter (18180): #6 _rootRun (dart:async/zone.dart:1354)
E/flutter (18180): #7 _CustomZone.run (dart:async/zone.dart:1258)
E/flutter (18180): #8 _CustomZone.runGuarded (dart:async/zone.dart:1162)
E/flutter (18180): #9 _invoke (dart:ui/hooks.dart:167)
E/flutter (18180): #10 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:259)
E/flutter (18180): #11 _drawFrame (dart:ui/hooks.dart:126)
E/flutter (18180):
E/flutter (18180): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: LateInitializationError: Local 'result' has not been initialized.
E/flutter (18180): #0 LateError._throwLocalNotInitialized (dart:_internal-patch/internal_patch.dart:208)
E/flutter (18180): #1 RenderObject.debugNeedsPaint (package:flutter/src/rendering/object.dart:2112)
E/flutter (18180): #2 _PageTurnWidgetState._captureImage (package:ssv1/book_screen/builders/widget.dart:40)
E/flutter (18180): #3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144)
E/flutter (18180): #4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1090)
E/flutter (18180): #5 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:998)
E/flutter (18180): #6 _rootRun (dart:async/zone.dart:1354)
E/flutter (18180): #7 _CustomZone.run (dart:async/zone.dart:1258)
E/flutter (18180): #8 _CustomZone.runGuarded (dart:async/zone.dart:1162)
E/flutter (18180): #9 _invoke (dart:ui/hooks.dart:167)
E/flutter (18180): #10 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:259)
E/flutter (18180): #11 _drawFrame (dart:ui/hooks.dart:126)
E/flutter (18180):
E/flutter (18180): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: LateInitializationError: Local 'result' has not been initialized.
E/flutter (18180): #0 LateError._throwLocalNotInitialized (dart:_internal-patch/internal_patch.dart:208)
E/flutter (18180): #1 RenderObject.debugNeedsPaint (package:flutter/src/rendering/object.dart:2112)
E/flutter (18180): #2 _PageTurnWidgetState._captureImage (package:ssv1/book_screen/builders/widget.dart:40)
E/flutter (18180): #3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144)
E/flutter (18180): #4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1090)
E/flutter (18180): #5 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:998)
E/flutter (18180): #6 _rootRun (dart:async/zone.dart:1354)
E/flutter (18180): #7 _CustomZone.run (dart:async/zone.dart:1258)
E/flutter (18180): #8 _CustomZone.runGuarded (dart:async/zone.dart:1162)
E/flutter (18180): #9 _invoke (dart:ui/hooks.dart:167)
E/flutter (18180): #10 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:259)
E/flutter (18180): #11 _drawFrame (dart:ui/hooks.dart:126)
E/flutter (18180):
E/flutter (18180): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: LateInitializationError: Local 'result' has not been initialized.
E/flutter (18180): #0 LateError._throwLocalNotInitialized (dart:_internal-patch/internal_patch.dart:208)
E/flutter (18180): #1 RenderObject.debugNeedsPaint (package:flutter/src/rendering/object.dart:2112)
E/flutter (18180): #2 _PageTurnWidgetState._captureImage (package:ssv1/book_screen/builders/widget.dart:40)
E/flutter (18180): #3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144)
E/flutter (18180): #4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1090)
E/flutter (18180): #5 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:998)
E/flutter (18180): #6 _rootRun (dart:async/zone.dart:1354)
E/flutter (18180): #7 _CustomZone.run (dart:async/zone.dart:1258)
E/flutter (18180): #8 _CustomZone.runGuarded (dart:async/zone.dart:1162)
E/flutter (18180): #9 _invoke (dart:ui/hooks.dart:167)
E/flutter (18180): #10 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:259)
E/flutter (18180): #11 _drawFrame (dart:ui/hooks.dart:126)
E/flutter (18180):
E/flutter (18180): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: LateInitializationError: Local 'result' has not been initialized.
E/flutter (18180): #0 LateError._throwLocalNotInitialized (dart:_internal-patch/internal_patch.dart:208)
E/flutter (18180): #1 RenderObject.debugNeedsPaint (package:flutter/src/rendering/object.dart:2112)
E/flutter (18180): #2 _PageTurnWidgetState._captureImage (package:ssv1/book_screen/builders/widget.dart:40)
E/flutter (18180): #3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144)
E/flutter (18180): #4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1090)
E/flutter (18180): #5 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:998)
E/flutter (18180): #6 _rootRun (dart:async/zone.dart:1354)
E/flutter (18180): #7 _CustomZone.run (dart:async/zone.dart:1258)
E/flutter (18180): #8 _CustomZone.runGuarded (dart:async/zone.dart:1162)
E/flutter (18180): #9 _invoke (dart:ui/hooks.dart:167)
E/flutter (18180): #10 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:259)
E/flutter (18180): #11 _drawFrame (dart:ui/hooks.dart:126)
E/flutter (18180):
E/flutter (18180): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: LateInitializationError: Local 'result' has not been initialized.
E/flutter (18180): #0 LateError._throwLocalNotInitialized (dart:_internal-patch/internal_patch.dart:208)
E/flutter (18180): #1 RenderObject.debugNeedsPaint (package:flutter/src/rendering/object.dart:2112)
E/flutter (18180): #2 _PageTurnWidgetState._captureImage (package:ssv1/book_screen/builders/widget.dart:40)
E/flutter (18180): #3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144)
E/flutter (18180): #4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1090)
E/flutter (18180): #5 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:998)
E/flutter (18180): #6 _rootRun (dart:async/zone.dart:1354)
E/flutter (18180): #7 _CustomZone.run (dart:async/zone.dart:1258)
E/flutter (18180): #8 _CustomZone.runGuarded (dart:async/zone.dart:1162)
E/flutter (18180): #9 _invoke (dart:ui/hooks.dart:167)
E/flutter (18180): #10 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:259)
E/flutter (18180): #11 _drawFrame (dart:ui/hooks.dart:126)

@sidetraxaudio
Copy link
Author

(The following has failed to resolve)
Downgrade to stable, cleanup, cache etc etc, copy to new project, compile with --no-shrink... all failed,

  • Debug works perfectly with zero output problems reported on real phone, emulator, windows and chrome builds.
  • Release compile fails on all platforms in exactly the same way.

@tuannvm2109
Copy link

After a while of edit and test, I have found a quick fix about this problem, you could change the function _captureImage to like this and it will work on release build, (You 'll need to copy this library to your own directory to edit PageTurnWidget file)

void _captureImage(Duration timeStamp) async {
await Future.delayed(const Duration(milliseconds: 20));
final pixelRatio = MediaQuery.of(context).devicePixelRatio;
final boundary =
_boundaryKey.currentContext?.findRenderObject() as RenderRepaintBoundary;
// if (boundary.debugNeedsPaint) {
// await Future.delayed(const Duration(milliseconds: 20));
// return _captureImage(timeStamp);
// }
final image = await boundary.toImage(pixelRatio: pixelRatio);
setState(() => _image = image);
}

@sidetraxaudio
Copy link
Author

Thanks mate - it works. I was hoping for better performance once I could get it to work in release mode but unfortunately its still unusably slow . I might look into how to make the performance better. If you find anything please make sure you post it.

@jmgeffroy
Copy link

Hi there! I'm writing 1 year later, but who knows, this can be interesting to someone: the original code snippet was probably this Gist. And it's very, very smooth.
I haven't found any relevant difference that might cause this huge difference, but I'll share if I find it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants