Fix FieldHelper.GetFieldOffset crash for classes with const fields (compile-time)

Inline call in `CreateScriptingObject` for perf
This commit is contained in:
Wojtek Figat
2023-10-10 20:52:12 +02:00
parent 902c82ae1e
commit ac542bf920

View File

@@ -429,6 +429,9 @@ namespace FlaxEngine.Interop
/// </summary>
internal static int GetFieldOffset(FieldInfo field, Type type)
{
if (field.IsLiteral)
return 0;
// Get the address of the field, source: https://stackoverflow.com/a/56512720
int fieldOffset = Unsafe.Read<int>((field.FieldHandle.Value + 4 + IntPtr.Size).ToPointer()) & 0xFFFFFF;
if (!type.IsValueType)
@@ -1308,7 +1311,7 @@ namespace FlaxEngine.Interop
internal object CreateScriptingObject(IntPtr unmanagedPtr, IntPtr idPtr)
{
object obj = CreateObject();
object obj = RuntimeHelpers.GetUninitializedObject(wrappedType);
if (obj is Object)
{
{
@@ -1332,7 +1335,7 @@ namespace FlaxEngine.Interop
return obj;
}
public static implicit operator Type(TypeHolder holder) => holder?.type ?? null;
public static implicit operator Type(TypeHolder holder) => holder?.type;
public bool Equals(TypeHolder other) => type == other.type;
public bool Equals(Type other) => type == other;
public override int GetHashCode() => type.GetHashCode();