Skip to content

Array uniforms wont work on Flutter web  #141296

@renancaraujo

Description

@renancaraujo

Steps to reproduce

  1. Create a Flutter project from scratch or use the simple shader sample.
  2. Add a fragment shader file and use array uniforms
  3. Try to run it on the web (flutter run -d chrome)

Expected results

It whould run the project normally.

Actual results

It fails as with an error message similar to:

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following IndexError was thrown during paint():
RangeError (index): Index out of range: index should be less than 3: 3

The relevant error-causing widget was:
  CustomPaint CustomPaint: [...]/lib/main.dart:34:37

When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:3       throw_
dart-sdk/lib/_internal/js_dev_runtime/private/js_array.dart 610:7                 _set]
lib/_engine/engine/canvaskit/painting.dart 368:5                                  setFloat
packages/flutter_shaders/src/set_uniforms.dart 62:5                               setFloat
packages/flutter_shaders/src/set_uniforms.dart 67:7                               setFloats
...

Code sample

Full example here:
https://github.com/renancaraujo/array_uniforms_issue

Code sample:

Code sample
// dart code
import 'dart:ui' as ui;

import 'package:flutter_shaders/flutter_shaders.dart';

// ...

  void paint(Canvas canvas, Size size) {
    shader.setFloatUniforms((value) {
      value.setSize(size);
      value.setFloats([
        0.1,
        0.2,
        0.3,
        0.4,
        0.5,
        0.6,
        0.7,
        0.8,
        0.9,
        1.0,
      ]);
    });

    final paint = Paint()..shader = shader;
    canvas.drawRect(
      Rect.fromLTWH(0, 0, size.width, size.height),
      paint,
    );
  }
// shader code

#include <flutter/runtime_effect.glsl>

uniform vec2 uSize;
uniform float[10] uFloats; // array uniform

out vec4 fragColor;

void main() { 
    vec2 pos = FlutterFragCoord().xy;
    vec2 uv = pos / uSize;


// ...

Screenshots or Video

No response

Logs

Logs
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following IndexError was thrown during paint():
RangeError (index): Index out of range: index should be less than 3: 3

The relevant error-causing widget was:
  CustomPaint CustomPaint: [...]/lib/main.dart:34:37

When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:3       throw_
dart-sdk/lib/_internal/js_dev_runtime/private/js_array.dart 610:7                 _set]
lib/_engine/engine/canvaskit/painting.dart 368:5                                  setFloat
packages/flutter_shaders/src/set_uniforms.dart 62:5                               setFloat
packages/flutter_shaders/src/set_uniforms.dart 67:7                               setFloats
...

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.5, on macOS 14.1.2 23B92 darwin-arm64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] VS Code (version 1.85.1)
[✓] Connected device (3 available)
[✓] Network resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listengineflutter/engine related. See also e: labels.found in release: 3.16Found to occur in 3.16found in release: 3.19Found to occur in 3.19has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions