BinomialLLC / basis_universal

Basis Universal GPU Texture Codec
Apache License 2.0
2.67k stars 260 forks source link

RuntimeError when encoding to UASTC with WASM #356

Open javagl opened 1 year ago

javagl commented 1 year ago

Description

The console shows

basis_encoder.wasm:0x36da2 Uncaught RuntimeError: memory access out of bounds
    at basis_encoder.wasm:0x36da2
    at basis_encoder.wasm:0x282a3
    at basis_encoder.wasm:0x14223
    at basis_encoder.wasm:0xb0c
    at basis_encoder.wasm:0xd7983
    at basis_encoder.wasm:0xd72a5
    at ClassHandle.BasisFile$getFileDesc [as getFileDesc] (eval at newFunc (basis_encoder.js:8:81985), <anonymous>:8:10)
    at dumpBasisFileDesc ((index):160:33)
    at dataLoaded ((index):230:3)
    at PNGDataLoaded ((index):471:3)

This happens on Chrome 116.0 and FireFox 117.0, and the same error appears when using the build output in Node.js, so it seems to be a general issue.

Possible solution

After a bunch of trial and error, I stumbled over https://github.com/emscripten-core/emscripten/issues/19268#issuecomment-1544298860 , and after changing the LINK_FLAGS in the CMakeLists.txt to include the STACK_SIZE like this...

LINK_FLAGS "--bind -s ALLOW_MEMORY_GROWTH=1 -O3 -s ASSERTIONS=0 -s INITIAL_MEMORY=299958272 -s MALLOC=emmalloc -s MODULARIZE=1 -s EXPORT_NAME=BASIS -s STACK_SIZE=10MB")

... the problem no longer appears.

If others confirm that this makes sense (or add details, like which other size than 10MB might be more appropriate), I can create a corresponding PR.

richgel999 commented 8 months ago

Hmm - that's a lot of stack, and this didn't happen before in my testing. I will investigate this. Thanks for the filing the issue.