Skip to content

App crashes when using ImageFilter.compose #120278

@olksij

Description

@olksij

Steps to Reproduce

  1. Execute flutter run -d macos on the code sample provided below
  2. App crashes.

Expected results

Image get painted and window won't crash

Actual results:

App crashes without catching any exception just throwing Call Stack in Debug Console

Code sample
import 'dart:ui' as UI;
import 'package:http/http.dart' as http;

import 'package:flutter/material.dart';

void main() => runApp(const MainApp());

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  static const url = 'https://docs.flutter.dev/assets/images/dash/Dash.png';

  static Future<UI.Image> loadImage() async {
    final response = await http.get(Uri.parse(url));
    return await decodeImageFromList(response.bodyBytes);
  }

  @override
  Widget build(context) => Directionality(
    textDirection: TextDirection.ltr, 
    child: FutureBuilder(
      future: loadImage(),
      builder: (_, snapchot) => snapchot.hasData
        ? Stack(children: [MyWidget(data: snapchot.data!,)])
        : const SizedBox(),
    )
  );
}

class MyWidget extends StatefulWidget {
  final UI.Image data;
  const MyWidget({super.key, required this.data});

  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> with TickerProviderStateMixin {
  @override
  Widget build(BuildContext context) => CustomPaint(painter: Painter(widget.data));
}

class Painter extends CustomPainter {
  final UI.Image image;

  Painter(this.image);
  
  @override
  void paint(Canvas canvas, Size size) {    
    final blurFilter = UI.ImageFilter.blur();
    final transformFilter = UI.ImageFilter.matrix(Matrix4.identity().storage);

    canvas.drawImage(image, Offset.zero, Paint()
        ..imageFilter = UI.ImageFilter.compose(inner: transformFilter, outer: blurFilter));
  }

  @override
  bool shouldRepaint(oldDelegate) => false;
}
flutter doctor -v
[✓] Flutter (Channel stable, 3.7.1, on macOS 13.2 22D49 darwin-arm64, locale en-SE)
    • Flutter version 3.7.1 on channel stable at /Users/oleksiibesida/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7048ed95a5 (7 days ago), 2023-02-01 09:07:31 -0800
    • Engine revision 800594f1f4
    • Dart version 2.19.1
    • DevTools version 2.20.1

[✓] 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

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

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.2 22D49 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 109.0.5414.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: crashStack traces logged to the consolec: fatal crashCrashes that terminate the processengineflutter/engine related. See also e: labels.found in release: 3.7Found to occur in 3.7found in release: 3.8Found to occur in 3.8has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions