Skip to content

Fix WebAssembly module initialization in worker.js#2

Open
gensym wants to merge 1 commit intomasterfrom
fix-worker-module-initialization
Open

Fix WebAssembly module initialization in worker.js#2
gensym wants to merge 1 commit intomasterfrom
fix-worker-module-initialization

Conversation

@gensym
Copy link

@gensym gensym commented Jun 24, 2025

Summary

Fixes the test page to work with the modularization

  • Fixed the "Module._malloc is not a function" error in worker.js
  • Updated module initialization to work with MODULARIZE=1 configuration
  • Added missing HEAPU8/HEAPU32 exports to the WebAssembly build

Problem

The worker.js file was expecting a global Module object, but the WebAssembly module is built with MODULARIZE=1, which wraps the module in a createSimplifyModule function instead. This caused runtime errors when trying to access Module functions like _malloc.

Solution

  1. Updated worker.js to properly initialize the module by calling createSimplifyModule()
  2. Made the relevant functions async to handle the asynchronous module initialization
  3. Added EXPORTED_RUNTIME_METHODS to the Makefile to export the required HEAP arrays

- Update worker.js to properly initialize the modularized WebAssembly module
- Use createSimplifyModule() instead of expecting a global Module object
- Make prepare_and_simplify and simplify functions async to handle initialization
- Add EXPORTED_RUNTIME_METHODS to Makefile to export HEAPU8 and HEAPU32

This fixes the "Module._malloc is not a function" error that occurred because
the WebAssembly module is built with MODULARIZE=1 flag.
@gensym gensym requested a review from neilpa-inv June 24, 2025 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants