Skip to content

[Web] [CanvasKit] WebGL context is not cleaned up / lost #50721

@cbenhagen

Description

@cbenhagen

When swiping through the pages in the example you see that they are disposed but the context is not lost / cleaned up. This leads to the following error:
Too many active WebGL contexts. Oldest context will be lost.

Notice how in this example the flutter logo disappears after the error occurred.

Related to #50719.

/cc @hterkelsen

import 'dart:html';
import 'dart:ui' as ui;

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  PageController pageController;

  @override
  void initState() {
    super.initState();
    pageController = PageController(initialPage: 1);
    ui.platformViewRegistry
        .registerViewFactory('xyz', (int viewId) => SpanElement());
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(),
        body: Column(
          children: [
            FlutterLogo(size: 48),
            Flexible(
              child: PageView.builder(
                controller: pageController,
                itemCount: 20,
                itemBuilder: (context, index) => Page(index: index,),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class Page extends StatefulWidget {
  const Page({
    Key key,
    this.index,
  }) : super(key: key);

  final int index;

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

class _PageState extends State<Page> {

  @override
  void dispose() {
    super.dispose();
    print('Page ${widget.index} disposed');
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Text('Page ${widget.index}'),
        Expanded(child: HtmlElementView(viewType: 'xyz')),
      ],
    );
  }
}
[✓] Flutter (Channel master, v1.15.4-pre.51, on Mac OS X 10.15.3 19D76, locale en-CH)
    • Flutter version 1.15.4-pre.51 at /Users/ben/flutter
    • Framework revision dc636069fc (6 hours ago), 2020-02-12 22:22:49 -0800
    • Engine revision e0ebaea590
    • Dart version 2.8.0 (build 2.8.0-dev.9.0 e4c39721c4)


[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/ben/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3.1, Build version 11C504
    • CocoaPods version 1.8.3

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

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 43.0.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

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

[✓] Connected device (3 available)
    • macOS      • macOS      • darwin-x64     • Mac OS X 10.15.3 19D76
    • Chrome     • chrome     • web-javascript • Google Chrome 80.0.3987.100
    • Web Server • web-server • web-javascript • Flutter Tools

• No issues found!

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listdependency: skiaSkia team may need to help use: web_canvaskitCanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Webengineflutter/engine related. See also e: labels.platform-webWeb applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions