Search Issue Tracker
Fixed in 2021.3.18f1
Fixed in 2021.3.X, 2022.2.X, 2023.1.X, 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
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
- Saving changes on the dirty VFX Graph during the Play mode throws "The referenced script (Unknown) on this Behaviour is missing!" warnings
- VFX Graph Debug Info overlaps the "Initialize" block debug info by default
Resolution Note (fix version 2023.1):
Fixed Marshal.OffsetOf returning invalid values in IL2CPP for misaligned fields on macOS.