MerlinVR / UdonSharp

An experimental compiler for compiling C# to Udon assembly
MIT License
678 stars 89 forks source link

When a property is defined, the return value of an unrelated public function becomes incorrect. #95

Closed kometaro-vr closed 3 years ago

kometaro-vr commented 3 years ago

As shown below, if a public method of ClassA with unrelated properties is called from ClassB, an incorrect value will be obtained.

environment:

code:

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class ClassA : UdonSharpBehaviour
{
    bool _foo;
    bool Foo
    {
        set { _foo = value; }
        get => _foo;
    }

    int _bar;
    int Bar
    {
        set { _bar = value; }
        get => _bar;
    }

    public bool GetBoolValue()
    {
        bool boolValue = true;
        Debug.Log("[ClassA] boolValue = " + boolValue.ToString());
        return boolValue;
    }

    public int GetIntValue()
    {
        int intValue = 12345;
        Debug.Log("[ClassA] intValue = " + intValue.ToString());
        return intValue;
    }
}
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class ClassB : UdonSharpBehaviour
{
    [SerializeField] ClassA _classA;

    public override void Interact()
    {
        Debug.Log("[ClassB] _classA.GetBoolValue() = " + _classA.GetBoolValue());
        Debug.Log("[ClassB] _classA.GetIntValue() = " + _classA.GetIntValue());
    }
}

result:

LOG: [ClassA] boolValue = True
LOG: [ClassB] _classA.GetBoolValue() = False
LOG: [ClassA] intValue = 12345
LOG: [ClassB] _classA.GetIntValue() = 0

Note that when I removed these properties from ClassA, the correct values were obtained.

ChanyaKushima commented 3 years ago

I fixed In #90.

MerlinVR commented 3 years ago

This should be fixed in https://github.com/MerlinVR/UdonSharp/releases/tag/v0.20.2