Skip to content

Web WASM: "RuntimeError: memory access out of bounds" when loading Godot game in iframe #150119

@uldall

Description

@uldall

Steps to reproduce

  1. Create Flutter application that opens Godot game in the WebViewWidget widget. For example this game.
  2. Build project using flutter build web --wasm.
  3. Open project in Chrome.

Note that a fix for webview_flutter_web is added to be able to use WebViewWidget with wasm.

Expected results

The game is shown like it is when not using --wasm:
image

Actual results

The error is shown and the Godot game is not loaded:
image

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_web/webview_flutter_web.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  WebViewController controller = WebViewController();

  _MyHomePageState() {
    if (WebViewPlatform.instance is WebWebViewPlatform) {
      final WebWebViewController webWebController =
          controller.platform as WebWebViewController;

      webWebController.setIFrameCredentialless(true);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: WebViewWidget(
          controller: controller
            ..loadRequest(Uri.parse(
                'https://godotengine.github.io/godot-demo-projects/2d/bullet_shower/'))),
    );
  }
}

Download the full sample here: https://github.com/uldall/wasmtestgodot

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
skwasm.wasm:0xa0a8 Uncaught RuntimeError: memory access out of bounds
    at skwasm.wasm:0xa0a8
    at skwasm.wasm:0x1e5318
    at w._surface_renderPicturesOnWorker (skwasm.js:129:388)
    at f (skwasm.js:61:400)
$free @ skwasm.wasm:0xa0a8
$surface_renderPicturesOnWorker @ skwasm.wasm:0x1e5318
w._surface_renderPicturesOnWorker @ skwasm.js:129
f @ skwasm.js:61

Flutter Doctor output

Doctor output
$ flutter doctor -v
[✓] Flutter (Channel stable, 3.22.2, on Fedora Linux 40 (Workstation Edition) 6.8.11-300.fc40.x86_64,
    locale en_US.UTF-8)
    • Flutter version 3.22.2 on channel stable at /home/uldall/git/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (7 days ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed
      instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✗] Linux toolchain - develop for Linux desktop
    ✗ clang++ is required for Linux development.
      It is likely available from your distribution (e.g.: apt install clang), or can be downloaded
      from https://releases.llvm.org/
    ✗ CMake is required for Linux development.
      It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded
      from https://cmake.org/download/
    ✗ ninja is required for Linux development.
      It is likely available from your distribution (e.g.: apt install ninja-build), or can be
      downloaded from https://github.com/ninja-build/ninja/releases
    • pkg-config version 2.1.0
    ✗ GTK 3.0 development libraries are required for Linux development.
      They are likely available from your distribution (e.g.: apt install libgtk-3-dev)

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed
      instructions).

[✓] VS Code (version 1.89.1)
    • VS Code at /var/lib/flatpak/app/com.visualstudio.code/x86_64/stable/active/files/extra/vscode
    • Flutter extension version 3.90.0

[✓] Connected device (1 available)
    • Linux (desktop) • linux • linux-x64 • Fedora Linux 40 (Workstation Edition)
      6.8.11-300.fc40.x86_64

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

! Doctor found issues in 4 categories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: buildBuilding flutter applications with the toole: wasmIssues related to the wasm build of Flutter Web.e: web_skwasmSkwasm rendering backend for webengineflutter/engine related. See also e: labels.found in release: 3.22Found to occur in 3.22found in release: 3.23Found to occur in 3.23has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: webviewThe WebView pluginpackageflutter/packages repository. See also p: labels.platform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-webOwned by Web platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-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