emscripten-core / emscripten-core/emscripten

glBufferData and glBufferSubData failing in workers when they used to not

Open
#16,688 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

**Version of emscripten/emsdk:**
emcc 3.1.8 I am getting the error, while in emcc 2.0.34 it worked fine (I updated and it broke the code)

I am trying to write some basic streaming code and I wrote a test example where a worker would populate the gl buffers and the main thread would render them, everything being properly mutexed. Here is the github link, it is extremely minimal (I tried to make it so, only like ~275 lines), here is the link https://github.com/yosmo78/EmscriptenWebGLStreamingTest

before there was syncronization issues inside the emscripten/webgl calls, in 2.0.34 as mentioned here https://github.com/emscripten-core/emscripten/issues/16404 but now it won't even let me buffer the data at all.

Any thoughts on how to make this possible?

**Failing command line in full:**
`em++ main.cpp -std=c++17 -sUSE_WEBGL2=1 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sWASM=1 -O3 -pthread -s PTHREAD_POOL_SIZE=1 -sALLOW_BLOCKING_ON_MAIN_THREAD -sOFFSCREEN_FRAMEBUFFER -sASYNCIFY -o index.js
`

**-v output**
```
"C:/emsdk/upstream/bin\clang++.exe" -target wasm32-unknown-emscripten -D__EMSCRIPTEN_SHARED_MEMORY__=1 -DEMSCRIPTEN -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=8 -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=C:\emsdk\upstream\emscripten\cache\sysroot -Xclang -iwithsysroot/include\compat -std=c++17 -v -O3 -pthread -matomics -mbulk-memory main.cpp -c -o C:\Users\yo76y\AppData\Local\Temp\emscripten_temp_daiqvjj9\main_0.o
clang version 15.0.0 (https://github.com/llvm/llvm-project 80ec0ebfdc5692a58e0832125f2c6a991df9d63f)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\emsdk\upstream\bin
(in-process)
"C:\\emsdk\\upstream\\bin\\clang++.exe" -cc1 -triple wasm32-unknown-emscripten -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-feature +atomics -target-feature +bulk-memory -target-feature +mutable-globals -target-feature +sign-ext -target-cpu generic -target-feature +atomics -target-feature +bulk-memory -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v "-fcoverage-compilation-dir=C:\\Users\\yo76y\\Desktop\\MinimalEmscripten2" -resource-dir "C:\\emsdk\\upstream\\lib\\clang\\15.0.0" -D __EMSCRIPTEN_SHARED_MEMORY__=1 -D EMSCRIPTEN -D __EMSCRIPTEN_major__=3 -D __EMSCRIPTEN_minor__=1 -D __EMSCRIPTEN_tiny__=8 -isysroot "C:\\emsdk\\upstream\\emscripten\\cache\\sysroot" -internal-isystem "C:\\emsdk\\upstream\\emscripten\\cache\\sysroot/include/wasm32-emscripten/c++/v1" -internal-isystem "C:\\emsdk\\upstream\\emscripten\\cache\\sysroot/include/c++/v1" -internal-isystem "C:\\emsdk\\upstream\\lib\\clang\\15.0.0\\include" -internal-isystem "C:\\emsdk\\upstream\\emscripten\\cache\\sysroot/include/wasm32-emscripten" -internal-isystem "C:\\emsdk\\upstream\\emscripten\\cache\\sysroot/include" -O3 -Werror=implicit-function-declaration -std=c++17 -fdeprecated-macro "-fdebug-compilation-dir=C:\\Users\\yo76y\\Desktop\\MinimalEmscripten2" -ferror-limit 19 -fmessage-length=120 -fvisibility default -pthread -fgnuc-version=4.2.1 -fcxx-exceptions -fignore-exceptions -fexceptions -fcolor-diagnostics -vectorize-loops -vectorize-slp -iwithsysroot/include/SDL "-iwithsysroot/include\\compat" -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o "C:\\Users\\yo76y\\AppData\\Local\\Temp\\emscripten_temp_daiqvjj9\\main_0.o" -x c++ main.cpp
clang -cc1 version 15.0.0 based upon LLVM 15.0.0git default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\emsdk\upstream\emscripten\cache\sysroot/include/wasm32-emscripten/c++/v1"
ignoring nonexistent directory "C:\emsdk\upstream\emscripten\cache\sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
C:\emsdk\upstream\emscripten\cache\sysroot/include/SDL
C:\emsdk\upstream\emscripten\cache\sysroot/include\compat
C:\emsdk\upstream\emscripten\cache\sysroot/include/c++/v1
C:\emsdk\upstream\lib\clang\15.0.0\include
C:\emsdk\upstream\emscripten\cache\sysroot/include
End of search list.
"C:/emsdk/upstream/bin\wasm-ld.exe" -o index.wasm C:\Users\yo76y\AppData\Local\Temp\emscripten_temp_daiqvjj9\main_0.o -LC:\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten C:\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\crtbegin.o -lGL-mt-webgl2-ofb -lal -lhtml5 -lstubs -lnoexit -lc-mt -ldlmalloc-mt -lcompiler_rt-mt -lc++-mt-noexcept -lc++abi-mt-noexcept -lsockets-mt -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --import-memory --shared-memory --export-if-defined=main --export-if-defined=_emscripten_thread_init --export-if-defined=_emscripten_thread_exit --export-if-defined=_emscripten_thread_crashed --export-if-defined=emscripten_tls_init --export-if-defined=pthread_self --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export=emscripten_stack_get_base --export=emscripten_stack_get_end --export=emscripten_stack_set_limits --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export=emscripten_dispatch_to_thread_ --export=_emscripten_thread_free_data --export=_emscripten_allow_main_runtime_queued_calls --export=emscripten_main_browser_thread_id --export=emscripten_main_thread_process_queued_calls --export=emscripten_run_in_main_runtime_thread_js --export=emscripten_builtin_memalign --export=malloc --export=free --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024
"C:/emsdk/upstream\bin\wasm-emscripten-finalize" index.wasm -o index.wasm --detect-features
"C:/emsdk/node/14.18.2_64bit/bin/node.exe" C:\emsdk\upstream\emscripten\src\compiler.js C:\Users\yo76y\AppData\Local\Temp\tmpy558zu8s.json
"C:/emsdk/upstream\bin\wasm-opt" --strip-dwarf --post-emscripten -O3 --low-memory-unused --asyncify --pass-arg=asyncify-imports@env.invoke_*,env.__call_main,env.emscripten_sleep,env.emscripten_wget,env.emscripten_wget_data,env.emscripten_idb_load,env.emscripten_idb_store,env.emscripten_idb_delete,env.emscripten_idb_exists,env.emscripten_idb_load_blob,env.emscripten_idb_store_blob,env.SDL_Delay,env.emscripten_scan_registers,env.emscripten_lazy_load_code,env.emscripten_fiber_swap,wasi_snapshot_preview1.fd_sync,env.__wasi_fd_sync,env._emval_await,env._dlopen_js,env.__asyncjs__* --zero-filled-memory --strip-debug --strip-producers index.wasm -o index.wasm --mvp-features --enable-threads --enable-mutable-globals --enable-bulk-memory --enable-sign-ext
"C:/emsdk/node/14.18.2_64bit/bin/node.exe" C:\emsdk\upstream\emscripten\tools\acorn-optimizer.js C:\Users\yo76y\AppData\Local\Temp\emscripten_temp_daiqvjj9\index.js AJSDCE minifyWhitespace
"C:/emsdk/node/14.18.2_64bit/bin/node.exe" C:\emsdk\upstream\emscripten\tools\acorn-optimizer.js C:\Users\yo76y\AppData\Local\Temp\tmp8cevzyq3.js emitDCEGraph noPrint
"C:/emsdk/upstream\bin\wasm-metadce" --graph-file=C:\Users\yo76y\AppData\Local\Temp\tmpeak0prlp.txt index.wasm -o index.wasm --mvp-features --enable-threads --enable-mutable-globals --enable-bulk-memory --enable-sign-ext
"C:/emsdk/node/14.18.2_64bit/bin/node.exe" C:\emsdk\upstream\emscripten\tools\acorn-optimizer.js C:\Users\yo76y\AppData\Local\Temp\tmpajsij48u.js applyDCEGraphRemovals minifyWhitespace
"C:/emsdk/node/14.18.2_64bit/bin/node.exe" C:\emsdk\upstream\emscripten\tools\acorn-optimizer.js C:\Users\yo76y\AppData\Local\Temp\emscripten_temp_daiqvjj9\index.js.jso.js.jso.js AJSDCE minifyWhitespace
"C:/emsdk/upstream\bin\wasm-opt" --strip-dwarf --minify-imports-and-exports-and-modules index.wasm -o index.wasm --mvp-features --enable-threads --enable-mutable-globals --enable-bulk-memory --enable-sign-ext
"C:/emsdk/node/14.18.2_64bit/bin/node.exe" C:\emsdk\upstream\emscripten\tools\acorn-optimizer.js C:\Users\yo76y\AppData\Local\Temp\tmpk2q9esuv.js applyImportAndExportNameChanges minifyWhitespace
"C:/emsdk/node/14.18.2_64bit/bin/node.exe" C:\emsdk\upstream\emscripten\tools\preprocessor.js C:\Users\yo76y\AppData\Local\Temp\emscripten_temp_daiqvjj9\settings.js worker.js --expandMacros
"C:/emsdk/node/14.18.2_64bit/bin/node.exe" C:\emsdk\upstream\emscripten\tools\acorn-optimizer.js C:\Users\yo76y\Desktop\MinimalEmscripten2\index.worker.js minifyWhitespace
```

Error:
```
worker sent an error! http://127.0.0.1:8080/
Uncaught TypeError: GLctx.bufferSubData is not a function

worker.onerror @ index.js:1
Uncaught ErrorEvent

Uncaught TypeError: GLctx.bufferSubData is not a function
at _emscripten_glBufferSubData (index.js:1:32103)
at index.wasm:0x7538
at index.wasm:0x8437
at index.wasm:0x49c3
at index.wasm:0xcf8c
at index.wasm:0x9406
at ret. (index.js:1:66526)
at Object.doRewind (index.js:1:67762)
at index.js:1:68354
at callUserCallback (index.js:1:40665)
```

I use:
```
if( EMSCRIPTEN_RESULT_SUCCESS != (res = emscripten_webgl_make_context_current(ctx) ) )
```
with a global context to give my pthread access to the functions

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.