-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Isolate.run is difficult to use because of #36983. When the closure provided to Isolate.run captures unnecessary stuff (because of that bug) that can't be send to an isolate, the user only sees this cryptic message:
[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Invalid argument(s): Illegal argument in isolate message: (object extends NativeWrapper - Library:'dart:ui' Class: Path)
#0 Isolate._spawnFunction (dart:isolate-patch/isolate_patch.dart:399:25)
#1 Isolate.spawn (dart:isolate-patch/isolate_patch.dart:379:7)
#2 Isolate.run (dart:isolate:232:15)
#3 _MyHomePageState._applySepiaFilterInIsolate (package:isoimg/main.dart:100:45)
It is not at all obvious that this is because the closure provided was over-capturing.
IMO, this is a major usability problem for Isolate.run because it is easy to use in a way that triggers the problem (especially in async/await contexts) and the solution is not clear from the error message.
Example where I ran into this: https://github.com/goderbauer/scratchpad/blob/8d82e738a4307c65651dc854ec6437002f69d6ed/isoimg/lib/main.dart#L90-L92
To make it work, one has to define a static method to avoid over-capturing: goderbauer/scratchpad@e36c311