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
- Too little validation messages in the "WebAssembly Language Features" Memory settings
- Project Settings Search Highlights are misaligned when using the Bitmap Text Rendering Mode
- "GetControlID at event ValidateCommand returns a controlID different from the one in Layout event" Warning is thrown when undoing the deletion of Sprite Shape Profile
- Memory related fields in the "WebAssembly Language Features" can be set to the negative numbers
- "WebAssembly Language Features" Header in the Player Settings has a smaller indentation
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.