Skip to content

Commit

Permalink
use GetFieldOffset instead of Marshal.OffsetOf to avoid bug on IL…
Browse files Browse the repository at this point in the history
…2CPP. (#9)
  • Loading branch information
quabug authored Aug 14, 2021
1 parent 2bbb147 commit ea47a81
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions Packages/blob-editor/Runtime/Builder/Builders.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Entities;
using UnityEngine;
Expand Down Expand Up @@ -57,10 +56,7 @@ public override unsafe void Build(BlobBuilder builder, ref T data)
var fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
for (var i = 0; i < Builders.Length; i++)
{
#if ENABLE_IL2CPP
#warning `Marshal.OffsetOf` may not work as expected with IL2CPP backend: https://issuetracker.unity3d.com/issues/marshal-dot-offsetof-returns-incorrect-offset-when-building-the-project-with-il2cpp-scripting-backend
#endif
var offset = Marshal.OffsetOf<T>(fields[i].Name).ToInt32();
var offset = UnsafeUtility.GetFieldOffset(fields[i]);
Builders[i].Build(builder, dataPtr + offset);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Packages/blob-editor/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.quabug.blob-editor",
"description": "Inspector-editor of blob asset",
"version": "1.1.1",
"version": "1.1.2",
"unity": "2020.3",
"displayName": "BlobEditor",
"dependencies": {
Expand Down

0 comments on commit ea47a81

Please sign in to comment.