Skip to content

Commit 47328ee

Browse files
committed
Lib: Fix thread safety in Il2CppBinary.GetFieldOffsetFromIndex
1 parent cc6dfc6 commit 47328ee

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

LibCpp2IL/Il2CppBinary.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,16 @@ public int GetFieldOffsetFromIndex(int typeIndex, int fieldIndexInType, int fiel
393393
if (ptr > 0)
394394
{
395395
var offsetOffset = (ulong)MapVirtualAddressToRaw(ptr) + 4ul * (ulong)fieldIndexInType;
396-
Position = (long)offsetOffset;
397-
offset = (int)ReadPrimitive(typeof(int))!; //Read 4 bytes. We can't just use ReadInt32 because that breaks e.g. Wasm. Hoping the JIT can optimize this as it knows the type.
396+
GetLockOrThrow();
397+
try
398+
{
399+
Position = (long)offsetOffset;
400+
offset = (int)ReadPrimitive(typeof(int))!; //Read 4 bytes. We can't just use ReadInt32 because that breaks e.g. Wasm. Hoping the JIT can optimize this as it knows the type.
401+
}
402+
finally
403+
{
404+
ReleaseLock();
405+
}
398406
}
399407
}
400408
else

0 commit comments

Comments
 (0)