Skip to content

[Impeller] Picture/Layer toImage doesn't work when application is backgrounded on iOS. #146990

@SShayashi

Description

@SShayashi

Overview

As the title suggests, when I run certain functions in the background, I get an Exception: operation failed exception. Where the same crashes as reported in #135245 occurred, this exception could also occur. This issue has a higher number of crashes in Firebase Crashlytics.

Steps to reproduce

  1. Run the sample code
  2. Tap the Text Button
  3. Go to background

Expected results

No crash occurs.

Actual results

The following exception occurs.

Debug service listening on ws://127.0.0.1:54190/m3UsC57y-70=/ws
Syncing files to device iPhone 14 Pro Max...
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: operation failed
sample code
import 'dart:ui' as ui;

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextButton(
              onPressed: () async {
                // Waiting to return to BACK GROUND
                await Future.delayed(const Duration(seconds: 3));
                final ui.PictureRecorder recorder = ui.PictureRecorder();
                final ui.Canvas canvas = ui.Canvas(recorder);
                canvas.scale(100, 100);
                final ui.Picture scaledPicture = recorder.endRecording();
                // Crashes when this line runs in the background
                ui.Image image = await scaledPicture.toImage(
                  100,
                  100,
                );
              },
              child: const Text('Text Button'),
            ),
          ],
        ),
      ),
    );
  }
}
flutter doctor -v
flutter doctor -v
[✓] Flutter (Channel stable, 3.19.2, on macOS 13.4 22F66 darwin-arm64, locale ja-JP)
    • Flutter version 3.19.2 on channel stable at /Users/01036096/fvm/versions/3.19.2
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7482962148 (7 weeks ago), 2024-02-27 16:51:22 -0500
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/01036096/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • ANDROID_HOME = /Users/01036096/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode14.1.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.15.2

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

[✓] Android Studio (version 2022.2)
    • 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 17.0.6+0-17.0.6b802.4-9586694)

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

[✓] Connected device (3 available)
    • iPhone 14 Pro Max (mobile) • 08DFB7BD-01AA-45DC-A8F3-9F61D45007E3 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 13.4 22F66 darwin-arm64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 123.0.6312.124

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

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work liste: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.found in release: 3.19Found to occur in 3.19found in release: 3.22Found to occur in 3.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions