Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

嵌套ValueType并且写了binder情况下,CLR绑定,编译选项Optimize Code=true,热更域里某种写法会引起值解析不正确 #689

Closed
xushunwang opened this issue Apr 14, 2022 · 0 comments

Comments

@xushunwang
Copy link

外部值类型定义如下:

public struct TestStructA
{
    public long value;
}

public struct TestStructB
{
    public TestStructA m1;
    public TestStructA m2;
    public TestStructA m3;
    public TestStructA m4;
    public TestStructA m5;
    public TestStructA m6;
    public TestStructA m7;
    public TestStructA m8;
    public TestStructA m9;

    public static TestStructB GetOne(TestStructA a)
    {
        TestStructB ret = default;
        ret.m1 = new TestStructA { value = 1 };
        ret.m2 = new TestStructA { value = 2 };
        ret.m3 = new TestStructA { value = 3 };
        ret.m4 = new TestStructA { value = 4 };
        ret.m5 = new TestStructA { value = 5 };
        ret.m6 = new TestStructA { value = 6 };
        ret.m7 = new TestStructA { value = 7 };
        ret.m8 = new TestStructA { value = 8 };
        ret.m9 = new TestStructA { value = 9 };

        return ret;
    }

    public override string ToString()
    {
        return $"{m1.value}|{m2.value}|{ m3.value}|{ m4.value}|{ m5.value}|{ m6.value}|{ m7.value}|{ m8.value}|{ m9.value}";
    }
}

对应写了binder

热更域里这么使用:

namespace HotFix
{
    public static class HotFixLauncher
    {
        public static void Test()
        {
            MinCirclePath path = new MinCirclePath();

            path.Test();
        }

    }

    public class MinCirclePath
    {
        private TestStructB mAttr;

        public void Test()
        {
            mAttr = GetAttr();

            Debug.Log(mAttr);
        }

        private TestStructB GetAttr()
        {
            var a = new TestStructA() { value = 5 };

            //这样写不会错
            //var ret = TestStructB.GetOne(a);
            //return ret;

            //这样直接返回就会错
            return TestStructB.GetOne(a);
        }
    }
}

做了CLR方法绑定,并且热更代码编译一定要勾选上Optimize Code为true才会错。
指令上看不勾选只多了
图片

1.6.7和2.0.2都有这个问题,unity2019.4

TestError.zip
例子工程里任意场景运行即可复现。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant