Skip to content

Commit

Permalink
Fixed #312
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Apr 1, 2020
1 parent 000ba1c commit b85a853
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ILRuntime/Runtime/Intepreter/ILIntepreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ public object Run(ILMethod method, object instance, object[] p)
case ObjectTypes.Object:
case ObjectTypes.FieldReference:
case ObjectTypes.ArrayReference:
{
mStack[a->Value] = CheckAndCloneValueType(mStack[a->Value], AppDomain);
}
frame.ManagedStackBase--;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion ILRuntimeTest/Adapters/TestVector3Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public override void RegisterCLRRedirection(ILRuntime.Runtime.Enviorment.AppDoma
{
ret = ILIntepreter.Minus(esp, 4);
var instance = ILIntepreter.GetObjectAndResolveReference(ret);
if (instance->ObjectType == ObjectTypes.StackObjectReference)
if (instance->ObjectType == ObjectTypes.ValueTypeObjectReference)
{
var dst = ILIntepreter.ResolveReference(instance);
var f = ILIntepreter.Minus(dst, 1);
Expand Down
19 changes: 18 additions & 1 deletion ILRuntimeTest/TestFramework/TestVector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,24 @@
using ILRuntime.Other;

namespace ILRuntimeTest.TestFramework
{
{
public struct TestVector3NoBinding
{
public float x, y, z;

public TestVector3NoBinding(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}

public override string ToString()
{
return $"({x},{y},{z})";
}
}

public struct TestVector3
{
public float X, Y, Z;
Expand Down
39 changes: 39 additions & 0 deletions TestCases/TestValueTypeBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,44 @@ public static void UnitTest_10035()
Console.WriteLine(i.ToString());
}
}

static TestVector3NoBinding m_curPos;

public static void UnitTest_10036()
{
TestVector3NoBinding rawPos = new TestVector3NoBinding(1, 2, 3);
TestVector3NoBinding tmpPos = rawPos;
m_curPos = rawPos;
Console.WriteLine("before raw:" + rawPos + " tmp:" + tmpPos + " cur:" + m_curPos);
ChangePosY(tmpPos);
ChangePosY(m_curPos);
Console.WriteLine("after raw:" + rawPos + " tmp:" + tmpPos + " cur:" + m_curPos);
if (tmpPos.y == 0 || m_curPos.y == 0)
throw new AccessViolationException();
}

static TestVector3 m_curPos2;
public static void UnitTest_10037()
{
TestVector3 rawPos = new TestVector3(1, 2, 3);
TestVector3 tmpPos = rawPos;
m_curPos2 = rawPos;
Console.WriteLine("before raw:" + rawPos + " tmp:" + tmpPos + " cur:" + m_curPos2);
ChangePosY2(tmpPos);
ChangePosY2(m_curPos2);
Console.WriteLine("after raw:" + rawPos + " tmp:" + tmpPos + " cur:" + m_curPos2);
if (tmpPos.Y == 0 || m_curPos2.Y == 0)
throw new AccessViolationException();
}

static void ChangePosY(TestVector3NoBinding pos)
{
pos.y = 0;
}

static void ChangePosY2(TestVector3 pos)
{
pos.Y = 0;
}
}
}

0 comments on commit b85a853

Please sign in to comment.