WebGL demangle support

In the process of porting a unity web-player app to WebGL I’m running into some issues:

There are runtime errors and the mangled stacktraces make it very hard to understand what is going on.
In the player settings I have enabled Soft Null exceptions and have set Scripting Define Symbols to “DEMANGLE_SUPPORT=1;ASSERTIONS=2”.
Yet I get warnings like these in my browser:
a problem occurred in builtin C++ name demangling; build with -s DEMANGLE_SUPPORT=1 to link in libcxxabi demangling
Build with ASSERTIONS=2 for more info.
I’m building via BuildPipeline.BuildPlayer with BuildOptions.AllowDebugging | BuildOptions.Development

These are the sort of stacktraces I get: Imgur: The magic of the Internet

What is the process of enabling demangling and getting proper stacktraces?
Is it possible to hook into the webGL build process at a certain stage?
It is very hard to construct a minimal failure case if it is hard to figure out where the error lies.

DEMANGLE_SUPPORT and ASSERTIONS are parameters passed to emscripten, not scripting defines. While it is possible to set these from an editor script: PlayerSettings.SetPropertyString(""emscriptenArgs"", ""-s DEMANGLE_SUPPORT=1"", BuildTargetGroup.WebGL);, this will not help much in your case, as this does not affect demangling of C# code. We will work on making this nicer, but you can usually tell the function names from the mangled strings as it is now fairly well.

From your stack trace, I can see that the failure you are looking at happened in a constructor of a class called something like Sessions.Node.

1 Like

Is the following kind of a parameter value correct?

PlayerSettings.SetPropertyString("emscriptenArgs", "-s DEMANGLE_SUPPORT=1 ASSERTIONS=2 -Werror", BuildTargetGroup.WebGL);

When I set the emscriptenArgs with the above I get the following areas:

Failed running “C:\Program Files (x86)\Unity 5.0.0b19\Editor\Data\PlaybackEngines\webglsupport/BuildTools/Emscripten_Win/python/2.7.5.3_64bit/python.exe” “C:\Program Files (x86)\Unity 5.0.0b19\Editor\Data\PlaybackEngines\webglsupport/BuildTools/Emscripten/emcc” @“C:/Users/sarahm/workspaces/sarahm_default/MiniConstruction/Unity5TestBranch/Unity/Assets/…/Temp/emcc_arguments.resp”

stdout:
WARNING: sanity check failed to run [Errno 13] Permission denied: ‘C:\Program Files (x86)\Unity 5.0.0b19\Editor\Data\PlaybackEngines\webglsupport/BuildTools/emscripten.config_sanity’
stderr:
WARNING root: did not see a source tree above the LLVM root directory (guessing based on directory of C:\Program Files (x86)\Unity 5.0.0b19\Editor\Data\PlaybackEngines\webglsupport/BuildTools/Emscripten_FastComp_Win\llc), could not verify version numbers match
INFO root: (Emscripten: Running sanity checks)
WARNING root: java does not seem to exist, required for closure compiler, which is optional (define JAVA in ~/.emscripten if you want it)
ERROR root: ASSERTIONS=2: No such file or directory (“ASSERTIONS=2” was expected to be an input file, based on the commandline arguments provided)

UnityEditor.HostView:OnGUI()

How do I properly include demangling, assertions and werror?

you would have to pass “-s ASSERTIONS=2” (the -s is important). That said, I don’t think that DEMANGLE_SUPPORT and ASSERTIONS=2 would provide much additional helpful information for debugging Unity builds. What is the actual issue you are trying to debug?

1 Like

Sorry for the late reply here. I was having trouble building a project and interfacing it with calls to page JavaScript. I have however gotten past this problem. I was asking mainly because I could add one define using the method you listed above but not all three (Demangle, Assertions and Werror).

Adding one define but not both is because you need the -s for both of them - ie, “-s DEMANGLE_SUPPORT=1 -s ASSERTIONS=2”, instead of “-s DEMANGLE_SUPPORT=1 ASSERTIONS=2”

1 Like

Ok I see now. Thank you for clearing that up.

On a related note: how can one set the WebGL exception handling level in an editor script?

PlayerSettings.SetPropertyInt("exceptionSupport", BuildTargetGroup.WebGL, i);

(Where i is a value from 0 to 2)

2 Likes

Thanks Jonas!

Small correction for the record…

You need to swap the last two arguments:

PlayerSettings.SetPropertyInt(“exceptionSupport”, i, BuildTargetGroup.WebGL);

Getting off-topic, but out of curiosity:

  • exceptionSupport 0 (‘None’) sets the emcc flag DISABLE_EXCEPTION_CATCHING=1

  • exceptionSupport 1 (‘Explicitly Thrown Exceptions Only’) and

  • exceptionSupport 2 (‘Full’)
    both set the emcc flag DISABLE_EXCEPTION_CATCHING=0

I couldn’t find a difference between the latter two in the emcc flags. So what causes the difference in error reporting?

DISABLE_EXCEPTION_CATCHING tells the emscripten compiler to generate try/catch blocks in the generated JavaScript code (which works, but will cause some code to to drop out of asm.js optimizations). If you enable “Full” exception support, we also emit code in IL2Cpp to do check for null on each reference access and throw a NullReferenceException if needed.

2 Likes