Search Issue Tracker
Fixed
Fixed in 2021.3.18f1, 2022.2.5f1, 2023.1.0a26
Votes
0
Found in
2022.2.0b14
2023.1.0a18
Issue ID
UUM-19622
Regression
Yes
Marshal.OffsetOf returns invalid value in IL2CPP for misaligned fields on macOS
Marshal.OffsetOf returns invalid value in IL2CPP for misaligned fields on macOS, .NET 7.0/ Unity Mono return correct value.
On 2022.2.0b14 on macOS (Arm) it prints:
"foo 1" under Mono (Editor and Standalone), and .NET 7.0
"foo 0" under IL2CPP
This was working previously at least in 2020.3, likely also in 2021.x
Reprocase is as following:
{code:c#}
[StructLayout(LayoutKind.Explicit, Size = 3)]
struct Repro
{
[FieldOffset(1)]
public ushort foo;
}
public void ReproCase()
{
foreach (var field in typeof(Repro).GetFields())
{
var offset = (uint) Marshal.OffsetOf(field.DeclaringType, field.Name).ToInt32();
Debug.LogWarning($"{field.Name} {offset}");
}
} {code}
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
- Inaccurate Box Collider boundaries on a rotated child Cube when the parent GameObject Scale is non-uniform
- [Android] "SHADOWS_SCREEN" set as shader Keyword when no "_ShadowMapTexture" is bound leads to freeze on a build on some Mali GPU devices
- Constant console errors when using Min/Max Slider in PlayMode
- The global scene list is overridden in a project built with command line when the Override Global Scene List setting is disabled in the build profile
- [Linux] AutoLocale log is logged when opening a project
Resolution Note (fix version 2023.1.0a26):
Fixed Marshal.OffsetOf returning invalid values in IL2CPP for misaligned fields on macOS.