Skip to content

Wasm32 symbol xxx without index value error

This is followup of my mail "WebAssembly compilation problems - Wasm32 symbol xxx without index value error" on fpc-devel, https://lists.freepascal.org/pipermail/fpc-devel/2023-March/045104.html .

Compiling Castle Game Engine for WebAssembly (OS = wasi, CPU = wasm32) fails with errors "Wasm32 symbol xxx without index value error".

The issue happens at unit X3DNodes and a few other inter-connected X3D* units. Admittedly this is a rather poor bugreport -- the unit X3DNodes is big and it's entangled with a few other non-trivial X3D* units. We have a few TODOs to split this code better (e.g. registration for X3DLoad*, move of X3D classic/xml parsers to separate units), but, well, everything takes time and we have lots of TODOs :) I'm submitting the issue in the hope that this information will be enough for an FPC developer to do some experiments and/or at least point us toward a clue what may be the error/workaround.

Steps to reproduce:

git clone https://github.com/castle-engine/castle-engine/ # get CGE from GitHub
cd castle-engine/
git checkout webassm_platformer_test # switch to branch where we test WebAssembly
cd examples/platformer/
./compile_web_assembly.sh

The last step runs a bash script that executes FPC with proper command-line options. It assumes you have installed cross-compiler from wasi/wasm32.

This fails right now (when used with FPC from main branch, at db66d8f0 , from host Linux/x86_64) like this:

Compiling /home/michalis/sources/castle-engine/castle-engine/src/scene/load/x3dloadinternalutils.pas
x3dloadinternalgeo.pas(234) Error: Wasm32 symbol X3DFIELDS/home/michalis/bin/fpcTSFFLOAT_$__$$_SETVALUE$SINGLE without index value error
x3dloadinternalgeo.pas(234) Error: Wasm32 symbol X3DFIELDS/home/michalis/bin/fpcTX3DSIMPLEMULTFIELD$3$CRC5146E438_CRCAB5A7799_$__$$_GETITEMS$$TINT32LIST without index value error
x3dloadinternalgeo.pas(234) Error: Wasm32 symbol X3DFIELDS/home/michalis/bin/fpcTX3DSIMPLEMULTFIELD$3$CRC5146E438_CRCAB5A7799_$__$$_GETITEMS$$TINT32LIST without index value error
x3dloadinternalgeo.pas(234) Error: Wasm32 symbol X3DFIELDS/home/michalis/bin/fpcTX3DSIMPLEMULTFIELD$3$CRC5146E438_CRCAB5A7799_$__$$_GETITEMS$$TINT32LIST without index value error
x3dloadinternalgeo.pas(234) Error: Wasm32 symbol X3DFIELDS/home/michalis/bin/fpcTX3DSIMPLEMULTFIELD$3$CRC5146E438_CRCAB5A7799_$__$$_GETITEMS$$TINT32LIST without index value error
x3dloadinternalgeo.pas(234) Fatal: There were 5 errors compiling module, stopping

Note that the middle of error mesage contains /home/michalis/bin/fpc which just happens to be how I execute FPC on my system. This seems to be unrelated bug in recent FPC main at message display, in some previous FPC versions it was just $_$.

A workaround for this problem in x3dloadinternalgeo.pas exists (in fact, removing x3dloadinternalgeo from "uses" clause of X3DLoad, and thus making it unnecessary for CGE, is easy). But doing so, leads to more and more similar "Wasm32 symbol .... without index value error" errors, that point all over the place to various classes in X3DFields. Sometimes a minor thing, like moving a property setter from protected->private, seems to workaround given occurrence of the problem... but then it pops in another place.

The only common thing I noticed is that the error happens when executing a method (or setting a property that uses a method as setter).

Note 1: If you want to go one step further with CGE, you can build CGE build tool, and build the project with it. To do this, do something like this from CGE root directory

export CASTLE_ENGINE_PATH=`pwd`
./tools/build-tool/castle-engine_compile.sh
mv tools/build-tool/castle-engine ~/bin/ # move castle-engine somewhere to your $PATH
cd examples/platformer/
castle-engine compile --os=wasi --cpu=wasm32
# or use "debug" mode (default is "release"):
castle-engine compile --os=wasi --cpu=wasm32 --mode=debug

Add --verbose to castle-engine compile ... command-line to see how it actually executes FPC, you will see it matches lines in ./compile_web_assembly.sh. Compiling like this results in the same errors "Wasm32 symbol ... without index value error".

Note 2: FPC for WebAssembly can compile successfully many other CGE units. E.g. compilation of this example goes OK:

examples/user_interface/view_events/
castle-engine compile --os=wasi --cpu=wasm32

So our compilation flags, and a lot of other units (with lots of classes and properties) seem OK. However, most CGE units use TCastleViewport, TCastleScene classes that in turn use X3DNodes and friends. The important CGE functonality (all 3D rendering, all 2D rendering in a viewport) relies on X3DNodes and friends.

Note 3: Some code on this CGE branch has been "hacked" just to test WebAssembly compilation. Don't count on it actually executing and doing anything sensible (on WebAssembly or even other targets :) ). Use our "master" branch if you want to test CGE unrelated to this bugreport.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information