Search Issue Tracker
By Design
Votes
0
Found in
2021.3.34f1
2022.3.17f1
2023.2.5f1
2023.3.0b3
6000.0.0b11
Issue ID
UUM-60501
Regression
No
"builtin functions must be directly called" errors are thrown when building for WebGL
How to reproduce:
1. Open the attached project "unity_project.zip"
2. Build the project for WebGL
Expected results: Build is successful
Actual results: Build fails with errors "builtin functions must be directly called"
Reproducible with: 2021.3.34f1, 2022.3.17f1, 2023.2.5f1, 2023.3.0b3
Reproducible on: Windows 10 22H2
Not reproducible on: No other environment tested
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- “Render Graph Execution error” errors are thrown when custom Renderer Feature enabled and Scene View is focused
- Terrain has tint from the directional light source when a normal map is enabled on iOS and Android Platforms
- [HDRP] Custom pass before post process
- [2D] Generate Outline will turn sprites a solid black
- Floating Editor Windows can become completely inaccessible when disconnecting monitor on multi-monitor setup
Resolution Note:
This is an unsupported use of the DllImport attribute. Native functions called through DllImport need to be compatible with .NET Platform Invoke(https://learn.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke).
Builtin compiler functions such as __builtin_expect, __builtin_clz, or __builtin_ctz cannot be called through function pointers/pinvoke but must be called directly by C/C++ code. Even if this was supported they wouldn't have the expected effect as the compiler uses them as hints to optimize code. This isn't possible when the function call crosses the managed/unmanaged code barrier.
As a workaround I would suggest moving all the C# functions(PutLE16, PutLE24, PutLE32, BitsLog2Floor, BitsCtz) that use the __builtin_* functions to a C or C++ file in "Assets/Plugins/WebGL" and instead call these functions from the C# code using the DllImport attribute.