Skip to content

Commit

Permalink
Fixed Ourpalm#717
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Oct 7, 2022
1 parent 7162f6b commit 07cd386
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
16 changes: 15 additions & 1 deletion ILRuntime/Runtime/Intepreter/RegisterVM/ILIntepreter.Register.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4214,7 +4214,7 @@ public unsafe partial class ILIntepreter
}
else
{
if (objRef->ObjectType == ObjectTypes.ValueTypeObjectReference)
if (objRef->ObjectType == ObjectTypes.ValueTypeObjectReference && IsValueTypeReferenceValid(objRef, type))
{
stack.ClearValueTypeObject(type, ILIntepreter.ResolveReference(objRef));
}
Expand Down Expand Up @@ -5314,6 +5314,20 @@ public unsafe partial class ILIntepreter
return stack.PopFrame(ref frame, esp);
}

bool IsValueTypeReferenceValid(StackObject* ptr, IType type)
{
ptr = ResolveReference(ptr);
if (ptr->ObjectType == ObjectTypes.ValueTypeDescriptor)
{
if (ptr->Value == type.TypeIndex)
return true;
else
return false;
}
else
return false;
}

void LoadFromFieldReferenceToRegister(ref RegisterFrameInfo info, object obj, int idx, short reg)
{
if (obj is ILTypeInstance)
Expand Down
2 changes: 1 addition & 1 deletion ILRuntimeTestBase/Adapters/TestVector3Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override void RegisterCLRRedirection(ILRuntime.Runtime.Enviorment.AppDoma
StackObject* ret;
if (isNewObj)
{
ret = ILIntepreter.Minus(esp, 1);
ret = esp;
Fixed64 vec;
var ptr = ILIntepreter.Minus(esp, 1);
var val = *(long*)&ptr->Value;
Expand Down
15 changes: 12 additions & 3 deletions TestCases/TestValueTypeBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ public class BaseObj
{
private Fixed64Vector2 fv2;

public void SetPos(int x, int y)
{
fv2.x = new ILRuntimeTest.TestFramework.Fixed64(x);
}

public BaseObj()
{
int x, y;
Expand Down Expand Up @@ -595,19 +600,23 @@ public TestRunTimeStack()
public void Run()
{
List<TestObj> list = new List<TestObj>();
for (int i = 0; i < 10000; i++)
for (int i = 0; i < 1000; i++)
{
var obj = new TestObj();
obj.SetPos(i, i);
list.Add(obj);
}

list.Sort((a, b) => {
if (a.V2.x > b.V2.x)
if (a.V2.x < b.V2.x)
return 1;
else if (a.V2.x < b.V2.x)
else if (a.V2.x > b.V2.x)
return -1;
return 0;
});

if (list[0].V2.x.RawValue != 999)
throw new Exception();
}
}

Expand Down

0 comments on commit 07cd386

Please sign in to comment.