Open jtmuller5 opened 2 years ago
I dug a little deeper and the issue seems to be something different.
In Debug mode, the web worker returns an actual List\<Uint8List>. In Profile/Release mode, postMessage returns an array [[Image_bytes], 3, error, TypeError: t is not a function]
This is causing the error from my first message. Now the question is why doesn't the web worker work in profile/release mode?
@jtmuller5 Thanks for the issue report. Based on what you described and a discussion with @sigmundch it sounds like one possibility is that dart2js is tree shaking away some type information in the presence of the web worker.
I see some code commented out, can you clarify that uncommenting these lines is required for the rerpo? https://github.com/jtmuller5/Flutter-Puzzle-Hack/blob/98ab3855678521d3c160eb7e536983dfa09193c6/lib/ui/home/home_view.dart#L207-L225
From your follow up message it sounds like the values being serialized in the message returned from the worker are not valid. I wanted to investigate it a little and I found that if I recompile the worker with a dart2js version: 2.17.0-150.0.dev it seems to work fine in release mode. It is possible this issue has already been fixed but I would like you to confirm? Could you try switching to the Flutter master channel and rebuild the worker with dart2js and then run your app?
Summary
I am using a web worker in a Flutter app to crop and resize an image. The web worker works fine in debug mode but not in profile or release mode.
dart2js -o worker.js worker.dart
to generate a worker.js fileThe issue shows up when I try to use "computedPieces" on the Flutter side.
Debug Mode: The runtimeType of "computedPieces" in Flutter is List\<dynamic> Profile/Release Mode: The runtimeType of "computedPieces" in Flutter is JsonArray\<dynamic>
Reproducing the Issue
I discovered this while building my submission to the Flutter Puzzle Hack. You can see and run my code in this repo.
When "Start" is pressed, the web worker is used to process the selected image. In debug mode, you won't see any errors and the image will be sliced into 9 pieces (8 of which will appear in the puzzle). In profile/release mode, the spinner will remain on screen and if you right-click -> inspect -> console, you'll see the following error: