Skip to content

BindingError: Expected null or instance of Picture, got an instance of Picture on Flutter Web Release Build (CanvasKit) #168797

Closed
@shirsh94

Description

@shirsh94

Steps to reproduce

Description:
In the release build of my Flutter Web application (using the CanvasKit renderer), I’m encountering the following runtime error in the browser console:

VM134 main.dart.js:3481 Uncaught Error: BindingError: Expected null or instance of Picture, got an instance of Picture
    at Q (canvaskit.js:101:251)
    at Xb (canvaskit.js:108:38)
    at cc.$b [as toWireType] (canvaskit.js:109:408)
    at Tb._drawPicture (canvaskit.js:116:8)
    at a.Canvas.drawPicture (canvaskit.js:49:299)
    at Qt.Mq (main.dart.js:32807:3)
    at mX.eJ (main.dart.js:32455:11)
    at Qt.mN (main.dart.js:32723:14)
    at Qt.ud (main.dart.js:32772:6)
    at Qt.Mo (main.dart.js:32774:12)

Important Context:

This issue only occurs in the release build (flutter build web --release), not in debug or profile mode.

The object is definitely a ui.Picture, created using ui.PictureRecorder.

The error suggests a type mismatch between Dart and the CanvasKit WASM layer, even though the object is correct on the Dart side.

Steps to Reproduce:

Create a ui.Picture using PictureRecorder.

Store or reuse the Picture in a widget or painter.

In release mode, try to draw it using canvas.drawPicture(...).

Expected Behavior:
The picture should render correctly without any runtime errors.

Actual Behavior:
In the release build, a BindingError is thrown, claiming the object is not a valid Picture, although it was created properly.

Flutter Version:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.5, on macOS 15.1.1 24B91 darwin-arm64, locale en-GB)
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/macos-android-setup for more details.
[✗] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS and macOS development.
      Download at: https://developer.apple.com/xcode/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
    ✗ CocoaPods not installed.
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      For installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] Connected device (2 available)
[✓] Network resources

Target Platform:
Flutter Web (CanvasKit renderer) — Release Mode

Browser:
(Please include browser name and version, e.g., Chrome 124, Edge 123, etc.)

Additional Notes:

This might be related to how objects are compiled/minified or optimized in release mode.

Possibly an issue with how CanvasKit/WASM bindings verify object instances.

Please advise if there's a workaround, or if further reproduction steps or a minimal example is required.

Expected results

VM134 main.dart.js:3481 Uncaught Error: BindingError: Expected null or instance of Picture, got an instance of Picture
    at Q (canvaskit.js:101:251)
    at Xb (canvaskit.js:108:38)
    at cc.$b [as toWireType] (canvaskit.js:109:408)
    at Tb._drawPicture (canvaskit.js:116:8)
    at a.Canvas.drawPicture (canvaskit.js:49:299)
    at Qt.Mq (main.dart.js:32807:3)
    at mX.eJ (main.dart.js:32455:11)
    at Qt.mN (main.dart.js:32723:14)
    at Qt.ud (main.dart.js:32772:6)
    at Qt.Mo (main.dart.js:32774:12)

Actual results

.

Code sample

Code sample
[Paste your code here]

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[Paste your output here]

Metadata

Metadata

Assignees

No one assigned

    Labels

    in triagePresently being triaged by the triage teamwaiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions