Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[web] CanvasKit crash after many TextPainter.layout() calls #84320

@bradchristie

Description

@bradchristie

Steps to Reproduce

  1. Run flutter create bug.
  2. Update the files as follows:
  • Add provider to pubspec .yaml:
dependencies:
  flutter:
    sdk: flutter
  provider: ^5.0.0
  • Replace main.dart with this code
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:provider/provider.dart';

const totalSprites = 400;

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

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

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

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  final myPainter = MyCustomPainter();
  final startTime = DateTime.now();

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
        create: (_) => MyCustomPainter(),
        child: Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: Center(
              child: Consumer<MyCustomPainter>(builder: (context,painter,_) =>
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Expanded(child: CustomPaint(painter: painter, child:Center())),
                Text('Running time:'),
                Text(
                  DateTime.now().difference(startTime).inSeconds.toString(),
                  style: Theme.of(context).textTheme.headline4,
                ),
              ],
            ),
          ),
        )));
  }
}

class MyCustomPainter extends ChangeNotifier implements CustomPainter {

  late Ticker _ticker;

  final sprites = [
    for (var i=1; i<=totalSprites; i++) MySprite(),
  ];

  MyCustomPainter() {
    _ticker = Ticker((_) { notifyListeners(); });
    _ticker.start();
  }

  @override
  void paint(Canvas canvas, Size size) {
    for (final s in sprites) {
      s.draw(canvas);
    }
  }

  @override
  bool? hitTest(Offset position) => null;

  @override
  SemanticsBuilderCallback? get semanticsBuilder => null;

  @override
  bool shouldRebuildSemantics(covariant CustomPainter oldDelegate) => shouldRepaint(oldDelegate);

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;

}

class MySprite {

  //  Originally this drew an animated box with a number.
  //  But putting the graphics on the screen is not necessary to
  //  reproduce the bug.
  void draw(Canvas canvas) {
    var span = TextSpan(text: 'X', style:TextStyle(fontSize: 8));
    var tp = TextPainter(text: span,
        textAlign: TextAlign.center,
        textDirection: TextDirection.ltr)..layout();
  }

}
  1. Run the program on Chrome with the canvaskit (default) renderer

Expected results:
Counter at the bottom of the screen increments once per second indefinitely.

Actual results:
Counter stops around 30 to 35, and the console log starts showing repeated CanvasKit exceptions

Logs
P:\FlutterProjects\canvaskitbug>flutter run -d chrome --verbose
[  +80 ms] executing: [P:\flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[ +468 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[   +2 ms] 02c026b03cd31dd3f867e5faeb7e104cce174c5f
[        ] executing: [P:\flutter/] git tag --points-at 02c026b03cd31dd3f867e5faeb7e104cce174c5f
[  +72 ms] Exit code 0 from: git tag --points-at 02c026b03cd31dd3f867e5faeb7e104cce174c5f
[   +1 ms] 2.2.1
[   +6 ms] executing: [P:\flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +57 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [P:\flutter/] git ls-remote --get-url origin
[  +49 ms] Exit code 0 from: git ls-remote --get-url origin
[   +1 ms] https://github.com/flutter/flutter.git
[ +141 ms] executing: [P:\flutter/] git rev-parse --abbrev-ref HEAD
[  +57 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[   +1 ms] stable
[  +82 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +2 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[   +3 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +53 ms] executing: p:\programs\AndroidSDK\platform-tools\adb.exe devices -l
[  +45 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +70 ms] executing: p:\programs\AndroidSDK\platform-tools\adb.exe devices -l
[  +11 ms] Skipping pub get: version match.
[ +115 ms] Generating P:\FlutterProjects\canvaskitbug\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java
[  +69 ms] List of devices attached
           emulator-5554          device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:1
[  +53 ms] Launching lib\main.dart on Chrome in debug mode...
[  +18 ms] List of devices attached
           emulator-5554          device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:1
[ +116 ms] Updating assets
[  +83 ms] Waiting for connection from debug service on Chrome...
[ +106 ms] <- reset
[   +6 ms] P:\flutter\bin\cache\dart-sdk\bin\dart.exe --disable-dart-dev
P:\flutter\bin\cache\artifacts\engine\windows-x64\frontend_server.dart.snapshot --sdk-root P:\flutter\bin\cache\flutter_web_sdk/
--incremental --target=dartdevc --debugger-module-names --experimental-emit-debug-metadata -DFLUTTER_WEB_AUTO_DETECT=true
--output-dill C:\Users\brad\AppData\Local\Temp\flutter_tools.ea72a1d5\flutter_tool.4ce9defc\app.dill --libraries-spec
file:///P:/flutter/bin/cache/flutter_web_sdk/libraries.json --packages
P:\FlutterProjects\canvaskitbug\.dart_tool\package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts
--track-widget-creation --filesystem-root C:\Users\brad\AppData\Local\Temp\flutter_tools.ea72a1d5\flutter_tools.473a1ec
--filesystem-scheme org-dartlang-app --initialize-from-dill build\b1b715402d823b7fd5c2b68d2edcb2ce.cache.dill.track.dill --platform
file:///P:/flutter/bin/cache/flutter_web_sdk/kernel/flutter_ddc_sdk_sound.dill --sound-null-safety
[   +8 ms] <- compile org-dartlang-app:/web_entrypoint.dart
[+17169 ms] Waiting for connection from debug service on Chrome... (completed in 17.3s)
[   +1 ms] Synced 28.4MB.
[        ] <- accept
[        ] Caching compiled dill
[+1086 ms] [CHROME]:
[   +1 ms] [CHROME]:DevTools listening on ws://127.0.0.1:56823/devtools/browser/ac7b0ee8-ee82-45e8-993d-b9c37674cc8e
[ +437 ms] DwdsInjector: Received request for entrypoint at http://localhost:56793/main_module.bootstrap.js
[  +12 ms] MetadataProvider: Loading debug metadata...
[  +21 ms] MetadataProvider: Loaded debug metadata (sound null safety)
[  +10 ms] DwdsInjector: Injected debugging metadata for entrypoint at http://localhost:56793/main_module.bootstrap.js
[+1806 ms] ChromeProxyService: Initializing expression compiler for main_module.bootstrap.js with sound null safety: true
[  +71 ms] DevHandler: Debug service listening on ws://127.0.0.1:57668/iRKGFYfb4oc=/ws

[  +32 ms] This app is linked to the debug service: ws://127.0.0.1:57668/iRKGFYfb4oc=/ws
[   +8 ms] Debug service listening on ws://127.0.0.1:57668/iRKGFYfb4oc=/ws
[        ]  Running with sound null safety
[   +4 ms]   To hot restart changes while running, press "r" or "R".
[        ] For a more detailed help message, press "h". To quit, press "q".
[+35600 ms] null
[   +7 ms] CanvasKit threw an exception while laying out the paragraph. The font was "null". Exception:
           RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[ +547 ms] ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
[   +5 ms] The following NativeJavaScriptObject object was thrown during paint():
[   +6 ms]   RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[   +2 ms] The relevant error-causing widget was:
[   +1 ms]   CustomPaint file:///P:/FlutterProjects/canvaskitbug/lib/main.dart:51:33
[        ] When the exception was thrown, this was the stack:
[        ] https://unpkg.com/[email protected]/bin/canvaskit.js 149:56                                                  Ma
[   +1 ms] https://unpkg.com/[email protected]/bin/canvaskit.js 219:103                                                 d
[   +1 ms] https://unpkg.com/[email protected]/bin/canvaskit.js 1:1
Paragraph$layout
[   +1 ms] C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/canvaskit/text.dart 573:18       layout
[        ] packages/flutter/src/painting/text_painter.dart 578:5                                                            layout
[   +3 ms] packages/canvaskitbug/main.dart 107:44                                                                           <fn>
[        ] packages/canvaskitbug/main.dart 107:44                                                                           draw
[        ] packages/canvaskitbug/main.dart 80:8                                                                             paint
[        ] packages/flutter/src/rendering/custom_paint.dart 563:12
[_paintWithPainter]
[   +3 ms] packages/flutter/src/rendering/custom_paint.dart 605:7                                                           paint
[        ] packages/flutter/src/rendering/object.dart 2317:7
[_paintWithContext]
[        ] packages/flutter/src/rendering/object.dart 187:12
paintChild
[        ] packages/flutter/src/rendering/box.dart 2795:14
defaultPaint
[        ] packages/flutter/src/rendering/flex.dart 1078:7                                                                  paint
[        ] packages/flutter/src/rendering/object.dart 2317:7
[_paintWithContext]
[   +3 ms] packages/flutter/src/rendering/object.dart 187:12
paintChild
[   +2 ms] packages/flutter/src/rendering/shifted_box.dart 79:14                                                            paint
[        ] packages/flutter/src/rendering/object.dart 2317:7
[_paintWithContext]
[        ] packages/flutter/src/rendering/object.dart 187:12
paintChild
[        ] packages/flutter/src/rendering/box.dart 2795:14
defaultPaint
[        ] packages/flutter/src/rendering/custom_layout.dart 409:5                                                          paint
[        ] packages/flutter/src/rendering/object.dart 2317:7
[_paintWithContext]
[        ] packages/flutter/src/rendering/object.dart 187:12
paintChild
[        ] packages/flutter/src/rendering/proxy_box.dart 140:14                                                             paint
[        ] packages/flutter/src/material/material.dart 551:11                                                               paint
[        ] packages/flutter/src/rendering/object.dart 2317:7
[_paintWithContext]
[        ] packages/flutter/src/rendering/object.dart 187:12
paintChild
[   +2 ms] packages/flutter/src/rendering/proxy_box.dart 140:14                                                             paint
[        ] packages/flutter/src/rendering/object.dart 394:12
pushLayer
[        ] packages/flutter/src/rendering/proxy_box.dart 1922:14                                                            paint
[        ] packages/flutter/src/rendering/object.dart 2317:7
[_paintWithContext]
[        ] packages/flutter/src/rendering/object.dart 187:12
paintChild
[        ] packages/flutter/src/rendering/proxy_box.dart 140:14                                                             paint
[        ] packages/flutter/src/rendering/object.dart 2317:7
[_paintWithContext]
[        ] packages/flutter/src/rendering/object.dart 187:12
paintChild
[        ] packages/flutter/src/rendering/proxy_box.dart 140:14                                                             paint
[        ] packages/flutter/src/rendering/object.dart 2317:7
[_paintWithContext]
[   +4 ms] packages/flutter/src/rendering/object.dart 139:10
           _repaintCompositedChild
[        ] packages/flutter/src/rendering/object.dart 100:5
           repaintCompositedChild
[   +1 ms] packages/flutter/src/rendering/object.dart 975:29
flushPaint
[        ] packages/flutter/src/rendering/binding.dart 464:19
drawFrame
[        ] packages/flutter/src/widgets/binding.dart 876:13
drawFrame
[        ] packages/flutter/src/rendering/binding.dart 328:5
           [_handlePersistentFrameCallback]
[        ] packages/flutter/src/scheduler/binding.dart 1144:15
           [_invokeFrameCallback]
[        ] packages/flutter/src/scheduler/binding.dart 1082:9
handleDrawFrame
[        ] packages/flutter/src/scheduler/binding.dart 998:5
[_handleDrawFrame]
[        ] C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/platform_dispatcher.dart 963:13  invoke
[        ] C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/platform_dispatcher.dart 152:5
invokeOnDrawFrame
[        ] C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine.dart 262:45                      <fn>
[        ] The following RenderObject was being processed when the exception was fired: RenderCustomPaint#3bae3
relayoutBoundary=up3:
[        ]   creator: CustomPaint ← Expanded ← Column ← Consumer<MyCustomPainter> ← Center ← _BodyBuilder ←
[        ]     MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ← AnimatedBuilder ←
[        ]     DefaultTextStyle ← AnimatedDefaultTextStyle ← ⋯
[        ]   parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight (can use size)
[        ]   constraints: BoxConstraints(0.0<=w<=929.0, h=860.0)
[        ]   size: Size(929.0, 860.0)
[        ] This RenderObject had the following child:
[        ]     child: RenderPositionedBox#33b78 relayoutBoundary=up4
[   +3 ms] ════════════════════════════════════════════════════════════════════════════════════════════════════
[+3026 ms] null
[   +2 ms] CanvasKit threw an exception while laying out the paragraph. The font was "null". Exception:
           RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[   +8 ms] null
[   +5 ms] CanvasKit threw an exception while laying out the paragraph. The font was "null". Exception:
           RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[   +7 ms] null
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[   +8 ms] null
[        ] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[   +6 ms] null
[        ] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +10 ms] null
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +14 ms] null
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +15 ms] null
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +16 ms] null
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +15 ms] null
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +14 ms] null
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +15 ms] null
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +16 ms] null
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +16 ms] null
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +18 ms] null
[        ] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +16 ms] null
[        ] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +11 ms] null
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +14 ms] null
[        ] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[   +7 ms] null
[   +1 ms] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
[  +10 ms] null
[        ] Another exception was thrown: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
Analyzing canvaskitbug...

   info - The value of the local variable 'tp' isn't used - lib\main.dart:105:9 - unused_local_variable

1 issue found. (ran in 8.4s)
[√] Flutter (Channel stable, 2.2.1, on Microsoft Windows [Version 10.0.19042.985], locale en-US)
    • Flutter version 2.2.1 at P:\flutter
    • Framework revision 02c026b03c (13 days ago), 2021-05-27 12:24:44 -0700
    • Engine revision 0fdb562ac8
    • Dart version 2.13.1

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at p:\programs\AndroidSDK
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = p:\programs\AndroidSDK
    • ANDROID_SDK_ROOT = p:\programs\AndroidSDK
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 1.8.0_242-release-1644-b01)

[√] IntelliJ IDEA Community Edition (version 2021.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3
    • Flutter plugin version 57.0.5
    • Dart plugin version 211.7233

[√] Connected device (3 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 8.0.0 (API 26) (emulator)
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 91.0.4472.77
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 90.0.818.56

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: typographyText rendering, possibly libtxtc: crashStack traces logged to the consolee: web_canvaskitCanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Webengineflutter/engine related. See also e: labels.found in release: 2.2Found to occur in 2.2has 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 version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions