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
- "Reset UI Builder Layout" functionality inconsistently changes Canva Size when "Match Game View" is enabled/disabled
- Texture Import Warnings are obscured by other Terrain Layer options in the Inspector
- Burst Inspector middle divider is jittering when resized with the Burst Inspector window docked
- JsonConvert conversion fails trying to call GetCallbackMethodsForType when [OnDeserialized] is used in a class
- Different text alignment in the column header in Entities "System" window
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.