Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 5411: Out of memory error in emscripten builds #5446

Merged
merged 2 commits into from Jan 4, 2021
Merged

Issue 5411: Out of memory error in emscripten builds #5446

merged 2 commits into from Jan 4, 2021

Conversation

aglitchman
Copy link
Contributor

@aglitchman aglitchman commented Jan 3, 2021

This pull request fixes the issue #5411 for Defold 1.2.178 (beta) which uses the latest Emscripten 2.0.11.

Detailed description

Starting from 2.0.10 the WebAssembly memory used by Emscripten programs is, by default, created in the wasm file and exported to JavaScript, and wasm ignores the value of Module.INITIAL_MEMORY. The IMPORTED_MEMORY=1 setting can be used to revert to the old behaviour. But, you can't set the heap size for wasm in runtime because the max memory size is baked into the wasm binary. The only way to fix that is to add the settings IMPORTED_MEMORY=1 and ALLOW_MEMORY_GROWTH=1 for wasm builds.

Asm.js runs well as before and it uses the value of Module.INITIAL_MEMORY for heap size because TOTAL_MEMORY was renamed to INITIAL_MEMORY some time ago.

And the value of Module.INITIAL_MEMORY should be set before loading of runtime (it's due to changes by #5211).

Copy link
Contributor

@JCash JCash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.
Only thing missing is the corresponding change in waf_dynamo.py (would be nice to have it all in the same PR)

Copy link
Contributor

@JCash JCash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@JCash JCash merged commit af6a29c into defold:beta Jan 4, 2021
@aglitchman
Copy link
Contributor Author

aglitchman commented Jan 5, 2021

@JCash I have been testing those new settings for HTML5 builds, and I have just found out that I can't set heap size for wasm in runtime less than 256MB. The error is:
wasm instantiation failed! LinkError: WebAssembly.instantiate(): memory import 384 is smaller than initial 4096, got 2048

Could you please test this case too?

The build option -s INITIAL_MEMORY=... should be set to the minimal value (32MB or something like that). Because I know that @AGulev sets the heap size for his games much lower than 256MB. And I do that, too.

pull bot pushed a commit to proteanblank/defold that referenced this pull request Jul 28, 2021
* Update WASM/Asm.js mem init to fix issue 5411

* Update emflags in waf_dynamo.py for HTML5 builds
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.

None yet

2 participants