Skip to content

FragmentProgram.fromAsset throws misleading exception #126829

@filiph

Description

@filiph

Is there an existing issue for this?

Steps to reproduce

  1. Create a Flutter app with a shader. For example, https://github.com/flutter/samples/tree/main/simple_shader.
  2. Edit pubspec.yaml so that the path to the shader is also included in the assets record:
...

flutter:
  # Add this.
  assets:
    - shaders/

  shaders:
    - shaders/simple.frag

Note that this can easily happen if one wants to have shaders next to related pictures, for example. In my case, I had a folder called assets/patterns/ which included pattern PNGs as well as a fragment shader for simple cross hatch patterns.

  1. Try running the program.

Expected results

Program runs. Or it fails at compile time, telling me something like "shader cannot be compiled since it's already included in the asset bundle".

Actual results

Program fails at runtime.

Exception: Asset 'shaders/simple.frag' does not contain valid shader data.

It looks like having the shader (even unintentionally) in assets prevents the mechanism behind shader support from firing.

The resulting error is a red herring. I spent an hour trying to "fix" the fragment shader.

Code sample

https://github.com/flutter/samples/blob/main/simple_shader/ + changes above

Screenshots or Video

No response

Logs

Logs
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Asset 'shaders/diagonal_crosshatch.frag' does not contain valid shader data.
#0      new FragmentProgram._fromAsset (dart:ui/painting.dart:4328:7)
#1      FragmentProgram.fromAsset.<anonymous closure> (dart:ui/painting.dart:4355:55)
#2      new Future.microtask.<anonymous closure> (dart:async/future.dart:280:37)
#3      _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#4      _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

Flutter Doctor output

Doctor output
[!] Flutter (Channel stable, 3.10.0, on macOS 13.3.1 22E772610a darwin-arm64, locale en-US)
    • Flutter version 3.10.0 on channel stable at /Users/filiph/fvm/versions/beta
    ! Warning: `flutter` on your path resolves to /Users/filiph/fvm/versions/stable/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/filiph/fvm/versions/beta. Consider adding /Users/filiph/fvm/versions/beta/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/filiph/fvm/versions/stable/bin/dart, which is not inside your current Flutter SDK checkout at /Users/filiph/fvm/versions/beta. Consider adding /Users/filiph/fvm/versions/beta/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 84a1e904f4 (6 days ago), 2023-05-09 07:41:44 -0700
    • Engine revision d44b5a94c9
    • Dart version 3.0.0
    • DevTools version 2.23.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc1)
    • Android SDK at /Users/filiph/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.76.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.3.1 22E772610a darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 113.0.5672.92

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listfound in release: 3.10Found to occur in 3.10found in release: 3.11Found to occur in 3.11has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions