From 1f3a7cf00f6a4da8335861376ad6781f78cb8d86 Mon Sep 17 00:00:00 2001 From: liiir1985 Date: Wed, 25 May 2022 21:47:46 +0800 Subject: [PATCH] Fixed #298 --- ILRuntime/Runtime/Intepreter/ILIntepreter.cs | 5 ++++ TestCases/TestValueTypeBinding.cs | 28 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/ILRuntime/Runtime/Intepreter/ILIntepreter.cs b/ILRuntime/Runtime/Intepreter/ILIntepreter.cs index a284e0e9..6e47c6d2 100644 --- a/ILRuntime/Runtime/Intepreter/ILIntepreter.cs +++ b/ILRuntime/Runtime/Intepreter/ILIntepreter.cs @@ -3546,6 +3546,11 @@ public object Run(ILMethod method, object instance, object[] p) else PushNull(objRef); } + else + { + if (objRef->ObjectType >= ObjectTypes.Object) + mStack[objRef->Value] = ((CLRType)type).CreateDefaultInstance(); + } } } diff --git a/TestCases/TestValueTypeBinding.cs b/TestCases/TestValueTypeBinding.cs index d2f5e0bf..db52b08c 100644 --- a/TestCases/TestValueTypeBinding.cs +++ b/TestCases/TestValueTypeBinding.cs @@ -523,5 +523,33 @@ private TestStructB GetAttr() return TestStructB.GetOne(a); } } + + public static void UnitTest_10050() + { + // 热更工程使用 + List structs = new List(); + for (int i = 0; i < 5; i++) + { + TestVector3NoBinding t = new TestVector3NoBinding(); + if (i % 2 != 0) + t.x = i; + structs.Add(t); + } + for (int i = 0; i < 5; i++) + { + var item = structs[i]; + Console.WriteLine(item.x); + if (i % 2 != 0) + { + if (item.x != i) + throw new Exception(); + } + else + { + if (item.x != 0) + throw new Exception(); + } + } + } } } \ No newline at end of file