godot: WebAssembly maximum memory 2GB causes Out of Memory error on iOS Safari 16.2

Godot version

4.0.dev (f382a2b)

System information

iOS 16.2 Safari, iPhone 13 Pro

Issue description

When exporting for Web and running on iOS 16.2 Safari, out of memory error occurs at WebAssembly.Memory initialization. This error comes because maximum argument is 2048MB which is quite bigger for iOS. When I changed WASM_MEM_MAX to 256MB for example at platform/web/detect.py: 197, the error disappeared.

    env.Append(LINKFLAGS=["-s", "WASM_MEM_MAX=256MB"])

Steps to reproduce

  1. Build Godot Web export with option module_raycast_enabled=no to disable WebAssembly SIMD usage which seems to be not yet supported on iOS Safari 16.2.
  2. Export minimal reproduction project to Web.
  3. Out of memory error log will be found on JavaScript console (reproduced).
  4. Change WASM_MEM_MAX to 256MB and rebuild Web export.
  5. Re-export minimal reproduction project.
  6. Rotating unlit white cube is correctly rendered (reproduced).

Minimal reproduction project

simple_rotating_white_cube.zip

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 9
  • Comments: 20 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@akien-mga I think github accidentally closed this issue, could you reopen it? This issue was originally about Godot starting with a too high web assembly memory requirement, which hasn’t been fixed by the linked PR.

While disabling the ray cast module due to the lack of simd support in wasm is also necessary, it isn’t a full solution to this problem.

Yeah we can probably disable the raycast module by default on Web, directly in detect.py.

I hadn’t really considered the memory footprint from including everything that can compile, so we might want to review other optional features to see if some would make sense to disable by default if we think that they’re very unlikely to be used for Web projects. This would need to be documented of course as some users can be taken aback when a feature that works on PC seems broken/missing on Web.

@akien-mga Should we use module_raycast_enabled=no for future official web builds? It’s only used for CPU-based occlusion culling, which I gather isn’t going to be used often in web projects (as most of them are 2D or simple 3D scenes, with relatively few triangles).

As a bonus, it’ll make web export templates smaller as Embree could possibly be excluded at the same time. We just need to update the documentation accordingly to mention occlusion culling won’t work in web exports.

In my testing WASM_MEM_MAX=256MB and module_raycast_enabled=no does allow Godot 4 games to start on iOS Safari. They seem to crash after a while though, but this could easily be a problem with Safari and not Godot. At least the games will start now 😃

image With module_raycast_enabled=no I managed to run it!

That is as far as I have gotten as well. With 256MB it loads and looks fine for a few seconds, then it crashes.

Should probably open an issue upstream: https://bugs.webkit.org/

That is as far as I have gotten as well. With 256MB it loads and looks fine for a few seconds, then it crashes.

@stefano-elysium Here is the debug template for web built by myself. web_debug.zip

I receive an error when running the test on ios, “Unhandled Promise Rejection: CompileError: WebAssembly.Module doesn’t parse at byte 5: can’t get Function local’s type in group 1, in function at index 34516”

That exception is caused by lack of WASM-SIMD implementation of iOS Safari 16.3 or earlier. Excluding module raycast while build by option module_raycast_enabled=no as written in first comment will remove that error. It seems that iOS Safari 16.4 adding WASM-SIMD support according to the release note. That may become a good news.