Skip to content

Illegal argument in isolate message that works or break without changing much of the code #59866

@stephane-archer

Description

@stephane-archer

this code works:

import 'package:image/image.dart' as img;

@immutable
class _AdjustColorIsolatemessage {
  final img.Image inputImage;
  final num brightness;
  const _AdjustColorIsolatemessage(this.inputImage, this.brightness);
}

void main () {
    img.Image editedImage =
        await compute<_AdjustColorIsolatemessage, img.Image>(
      (message) {
        return img.adjustColor(
            // convert to 8-bit because adjustColor doesn't support 16-bit images
            message.inputImage.convert(format: img.Format.uint8),
            brightness: message.brightness);
      },
      _AdjustColorIsolatemessage(resizeImage, brightness),
    );
}

but moving the function executed by compute to it's own function result in the following error:

ArgumentError (Invalid argument(s): Illegal argument in isolate message: object is unsendable - Library:'dart:async' Class: _Future@5048458 (see restrictions listed at `SendPort.send()` documentation for more information)
 <- Instance of 'AsyncNotifierProviderElement<_RefImageEditedBeforeLutPathNotifier, String?>' (from package:riverpod/src/async_notifier.dart)
 <- Instance of '_RefImageEditedBeforeLutPathNotifier' (from package:lutme/ref_image_edited_before_lut_path_provider.dart)
 <- Closure: (_AdjustColorIsolatemessage) => Image from Function 'foo':. (from package:lutme/ref_image_edited_before_lut_path_provider.dart)
 <- field callback in compute.<anonymous closure> (from package:flutter/src/foundation/_isolates_io.dart)
 <- resultPort in Instance of '_RemoteRunner<Image>' (from dart:isolate)
)

Here is the new code:

import 'package:image/image.dart' as img;

@immutable
class _AdjustColorIsolatemessage {
  final img.Image inputImage;
  final num brightness;
  const _AdjustColorIsolatemessage(this.inputImage, this.brightness);
}

void main () {
    img.Image editedImage =
        await compute<_AdjustColorIsolatemessage, img.Image>(
       foo,
      _AdjustColorIsolatemessage(resizeImage, brightness),
    );
}

  img.Image foo(_AdjustColorIsolatemessage message) {
    return img.adjustColor(
        // convert to 8-bit because adjustColor doesn't support 16-bit images
        message.inputImage.convert(format: img.Format.uint8),
        brightness: message.brightness);
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-proposaltype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions