Error compiling panda3d with webgl

I’m trying to build panda3d with webgl following the instructions here: https://rdb.name/panda3d-webgl.md
I was able to fix a bunch of issues already, but no got stuck with this error:

built/include/cmath.I:431:10: warning: use of infinity is undefined behavior due to the currently enabled floating-point options [-Wnan-infinity-disabled]
  431 |   return std::numeric_limits<double>::infinity();
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from panda/src/pipeline/p3pipeline_composite1.cxx:12:
In file included from panda/src/pipeline/cycleDataLockedStageReader.cxx:14:
In file included from panda/src/pipeline/cycleDataLockedStageReader.h:62:
panda/src/pipeline/cycleDataLockedStageReader.I:187:17: error: no member named '_cycler' in 'CycleDataLockedStageReader<CycleDataType>'
  187 |   _pointer(from._cycler)
      |            ~~~~ ^
2 warnings and 1 error generated.
The following command returned a non-zero value: em++ -std=gnu++11 -ftemplate-depth-70 -fPIC -c -o built/tmp/p3pipeline_composite1.o -Ibuilt/tmp -Ibuilt/include -DLINK_ALL_STATIC= -Ipanda/src/pipeline -fno-exceptions -s DISABLE_EXCEPTION_CATCHING=1 -fno-rtti -fno-strict-aliasing -ffast-math -fno-stack-protector -O3 -DNDEBUG -Wall -Wno-unused-function -Werror=return-type -Wno-unused-variable -DBUILDING_PANDA panda/src/pipeline/p3pipeline_composite1.cxx
Storing dependency cache.
Elapsed Time: 31 sec
Build process aborting.
Build terminated.
2 warnings generated.
2 warnings generated.
2 warnings generated.

As I had lots of issues, I started to build a Docker container to be able to reproduce the working setup:

FROM alpine:3.13
 
WORKDIR /home

RUN apk add --no-cache python3 py3-pip git tar unzip wget
RUN apk add xz xz-doc
RUN apk add build-base # g++
RUN apk add gcompat # fix emscripten clang
RUN apk add linux-headers # for <linux/futex.h>
RUN apk add nodejs npm
RUN apk add nano # debugging / convenience

COPY . .

# setup for emscripten (version number or 'latest')
RUN VERSION="latest" && \
    git clone --recursive https://github.com/emscripten-core/emsdk.git emscripten_sdk && \
    cd emscripten_sdk && \
    git pull && \
    source emsdk_env.sh && \
    emsdk install ${VERSION} && \
    emsdk activate ${VERSION} && \
    # python script changes nodejs path in .emscripten file to 'node':
    python3 /home/parse_dot_emscripten.py && \
    source emsdk_env.sh

RUN python3.8 -m pip install --upgrade pip setuptools wheel # otherwise interrogate fails
RUN python3.8 -m pip install panda3d-interrogate

# install panda3d-webgl
RUN git clone https://github.com/panda3d/panda3d.git panda3d-webgl
RUN cd panda3d-webgl && \
    wget --no-check-certificate https://rdb.name/webgl-editor-and-dependencies.zip && \
    unzip webgl-editor-and-dependencies.zip && \
    python3.8 makepanda/makepanda.py --nothing --use-python --use-vorbis --use-bullet --use-zlib --use-freetype --use-harfbuzz --use-openal --no-png --use-direct --use-gles2 --optimize 4 --static --target emscripten --threads 4

In case you want to reproduce my error, here is the python script that changes the path to nodejs:

# read '.emscripten' file, save to dict
dems_dict = {}
with open('/home/emscripten_sdk/.emscripten', 'r') as dems:
	lines = dems.readlines()
for line in lines[1:]:
	try:
		key, value = line.split(' = ')
		dems_dict[key] = value
	except:
		pass

# modify the path to 'node'
dems_dict['NODE_JS'] = "'node'\n"

# rewrite new '.emscripten' file
with open('/home/emscripten_sdk/.emscripten', 'w') as dems:
	dems.write('import os\n')
	for key, value in dems_dict.items():
		dems.write(f'{key} = {value}')`

Any help would be appreciated!

Hi, imho building webgl port or using are two different things

  • if you want to build and help porting effort i suggest you use either “tot” version of emscripten ( marked devel here emscripten/ChangeLog.md at main · emscripten-core/emscripten · GitHub ) or current pyodide build pick ( 3.1.58 currently ).

    + python 3.12 which is the only and last python version certified to support emscripten and dynamic loading.

Using 3.12 allows you to enter pyodide and pygbag ecosystems which provide wheels for hard to build modules like numpy, pyglm …
3.13 free threading is unofficially supported on pygbag with some wheels and offers better performances on web.

nb: if you don’t want spend too much time to build Panda3D required third Parties (including python host+wasm )you can find emscripten toolchain with all deps precompiled to wasm here Releases · pygame-web/python-wasm-sdk · GitHub

also there’s a web build help thread on Panda3D discord Discord , Panda3D discord is there Panda3D

FWIW, this issue should already be fixed on the master branch as of some time ago.

I also updated the instructions and zip file, they were too outdated to work. It’s now building on top of Python 3.12.