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

生成CLRBinding时抛出NullReferenceException #263

Closed
cat12221 opened this issue Feb 21, 2019 · 0 comments
Closed

生成CLRBinding时抛出NullReferenceException #263

cat12221 opened this issue Feb 21, 2019 · 0 comments

Comments

@cat12221
Copy link

` public struct Fixed64Vector3
{
public Fixed64 x;
public Fixed64 y;
public Fixed64 z;

    public static readonly Fixed64Vector3 Zero3;

    public Fixed64Vector3(int x, int y, int z)
    {
        this.x = new Fixed64(x);
        this.y = new Fixed64(y);
        this.z = new Fixed64(z);
    }

    static Fixed64Vector3()
    {
        Zero3 = new Fixed64Vector3(0, 0, 0);
    }
}


public struct Fixed64
{
    private long m_rawValue;

    public static readonly Fixed64 Zero;

    public Fixed64(long value)
    {
        m_rawValue = value;
    }

    static Fixed64()
    {
        Zero = new Fixed64(0);
    }
}`

NullReferenceException: Object reference not set to an instance of an object
ILRuntime.Runtime.Intepreter.ILIntepreter.Execute (ILRuntime.CLR.Method.ILMethod method, ILRuntime.Runtime.Stack.StackObject* esp, System.Boolean& unhandledException) (at Assets/ILRuntime/Runtime/Intepreter/ILIntepreter.cs:2043)
Rethrow as ILRuntimeException: Object reference not set to an instance of an object
IL_0008: stsfld Numerics.FixedTest.Fixed64 Numerics.FixedTest.Fixed64::Zero
Numerics.FixedTest.Fixed64..cctor()


Fixed64类型InitializeFields下面这行代码执行中
staticInstance = new ILTypeStaticInstance(this)
由于.cctor中的这行指令
IL_0009: stsfld valuetype Numerics.FixedTest.Fixed64Vector3 Numerics.FixedTest.Fixed64Vector3::Zero
触发了 t.StaticInstance.AssignFromStack,但此时staticInstance为null。

Fixed64放到Fixed64Vector3之前就可避免异常,希望有帮助

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