godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
86.31k stars 19.21k forks source link

[Web] "Maximum call stack exceeded" with `dev_build=yes` on Quest browser #93476

Open dsnopek opened 1 week ago

dsnopek commented 1 week ago

Tested versions

Reproducible on:

System information

Meta Quest 3, Meta Quest Browser, Emscripten 3.1.61

Issue description

Using dev_build=yes with a web build, Godot crashes with "Maximum call stack exceeded" right after start up.

When building without dev_build=yes, then everything works fine!

Via git bisect, I've discovered that 37cf266b578864096bb7160c4f14fa8ac61fc38b is the first revision to introduce the issue.

It's a relatively weird commit to cause the problem, because it's just changing the order that platform specific flags are applied. However, maybe dev_build=yes was supposed to override something that after that change it doesn't? I still need to experiment with that part.

UPDATE: See my further research below!~

Steps to reproduce

Minimal reproduction project (MRP)

I've been testing with this project: https://gitlab.com/snopek-games/godot4-webxr-demo

AThousandShips commented 1 week ago

~Can you try if it works with this line not dependent on threads?~ https://github.com/godotengine/godot/blob/04bf7d4cade645a5923cc80d87ac1c6109e2cdfe/platform/web/detect.py#L222-L229

~Don't know if thread related specifically but that's another change recently~

Edit: nvm thought threads were already disabled by default on web

dsnopek commented 1 week ago

Using verbose=yes, I grabbed build commands (one compilation, one linking) to see the flags before and after 37cf266b578864096bb7160c4f14fa8ac61fc38b.

Before:

em++ -o core/error/error_macros.web.template_debug.dev.wasm32.o -c -std=gnu++17 -fno-exceptions -s USE_PTHREADS=1 -gdwarf-4 -g3 -Os -Wall -Wshadow-field-in-constructor -Wshadow-uncaptured-local -Wno-ordered-compare-function-pointers -DDEBUG_ENABLED -DDEV_ENABLED -DWEB_ENABLED -DUNIX_ENABLED -DGLES3_ENABLED -DJAVASCRIPT_EVAL_ENABLED -DPTHREAD_NO_RENAME -DMINIZIP_ENABLED -DBROTLI_ENABLED -DTHREADS_ENABLED -DCLIPPER2_ENABLED -DZSTD_STATIC_LINKING_ONLY -Ithirdparty/zstd -Ithirdparty/zlib -Ithirdparty/clipper2/include -Ithirdparty/brotli/include -Iplatform/web -I. core/error/error_macros.cpp

em++ -o bin/godot.web.template_debug.dev.wasm32.js --profiling-funcs -s INITIAL_MEMORY=32MB -s USE_WEBGL2=1 -s OFFSCREEN_FRAMEBUFFER=1 -s GL_ENABLE_GET_PROC_ADDRESS=1 -s STACK_SIZE=5120KB -s USE_PTHREADS=1 -s DEFAULT_PTHREAD_STACK_SIZE=2048KB -s PTHREAD_POOL_SIZE=8 -s WASM_MEM_MAX=2048MB -s WASM_BIGINT -s ENVIRONMENT=web,worker -s MODULARIZE=1 -s EXPORT_NAME='Godot' -s ALLOW_MEMORY_GROWTH=1 -s INVOKE_RUN=0 -s EXPORTED_RUNTIME_METHODS=['callMain','cwrap'] -s EXIT_RUNTIME=1 -s GL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0 --js-library /home/dsnopek/Sync/Projects/default/godot-4/modules/webxr/native/library_godot_webxr.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/modules/websocket/library_godot_websocket.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/modules/webrtc/library_godot_webrtc.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_audio.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_display.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_fetch.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_os.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_runtime.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_input.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_webgl2.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_javascript_singleton.js ...

After:

em++ -o core/error/error_macros.web.template_debug.dev.wasm32.o -c -std=gnu++17 -fno-exceptions -s USE_PTHREADS=1 -gdwarf-4 -g3 -O0 -Wall -Wshadow-field-in-constructor -Wshadow-uncaptured-local -Wno-ordered-compare-function-pointers -DDEBUG_ENABLED -DDEV_ENABLED -DWEB_ENABLED -DUNIX_ENABLED -DGLES3_ENABLED -DJAVASCRIPT_EVAL_ENABLED -DPTHREAD_NO_RENAME -DMINIZIP_ENABLED -DBROTLI_ENABLED -DTHREADS_ENABLED -DCLIPPER2_ENABLED -DZSTD_STATIC_LINKING_ONLY -Ithirdparty/zstd -Ithirdparty/zlib -Ithirdparty/clipper2/include -Ithirdparty/brotli/include -Iplatform/web -I. core/error/error_macros.cpp

em++ -o bin/godot.web.template_debug.dev.wasm32.js --profiling-funcs -s INITIAL_MEMORY=32MB -s USE_WEBGL2=1 -s OFFSCREEN_FRAMEBUFFER=1 -s GL_ENABLE_GET_PROC_ADDRESS=1 -s STACK_SIZE=5120KB -s USE_PTHREADS=1 -s DEFAULT_PTHREAD_STACK_SIZE=2048KB -s PTHREAD_POOL_SIZE=8 -s WASM_MEM_MAX=2048MB -s WASM_BIGINT -s ENVIRONMENT=web,worker -s MODULARIZE=1 -s EXPORT_NAME='Godot' -s ALLOW_MEMORY_GROWTH=1 -s INVOKE_RUN=0 -s EXPORTED_RUNTIME_METHODS=['callMain','cwrap'] -s EXIT_RUNTIME=1 -s GL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0 --js-library /home/dsnopek/Sync/Projects/default/godot-4/modules/webxr/native/library_godot_webxr.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/modules/websocket/library_godot_websocket.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/modules/webrtc/library_godot_webrtc.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_audio.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_display.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_fetch.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_os.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_runtime.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_input.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_webgl2.js --js-library /home/dsnopek/Sync/Projects/default/godot-4/platform/web/js/libs/library_godot_javascript_singleton.js ...

The only difference appears to be -Os changing to -O0: so, switching from optimizing for size, to no optimizations.

If I change my build command to scons platform=web target=template_debug dev_build=yes optimize=size, then, sure enough, it works!

But I guess we probably actually want no optimizations with dev_build=yes, except that it unfortunately seems to lead to exceeding the maximum call stack size on the Quest browser. :-/ I'm not sure what the right solution should be here?

@adamscott @Faless What do you think?