Issue with the new Unity update (Mono Compiler)?
See original GitHub issueBefore the Unity update, _GrandparentTest() (see below code) would work as expected (only A.Test() would be called). Now, no matter how I attempt this, the class that is most recent in the inheritance list (C, in this case), is the one referenced.
In other words, _GrandparentTest() is now synonymous with calling C.Test() (which then calls B.Test(), then A.Test()), when it should only be calling A.Test(). This creates a stack overflow when, for example, you want to call the grandparent update method (effectively, “base.base.Update()” instead of “base.Update()”) of a class because Unity now erroneously thinks _GrandparentUpdate() should point to “this.Update()” instead of what would be (if it were possible) “base.base.Update()”.
This seems like a bug with the Mono compiler? Am I missing something? This works fine as a console program in .NET Core and .NET Framework 3.5, 4, 4.5, and 4.8 (I didn’t bother testing any others) - and, again, it worked after last year’s Unity upgrade as well.
namespace Test
{
using System;
public class Program
{
private static Action _GrandparentTest = null;
private static Type _ParentType = null;
private static IntPtr method_ptr;
public static void Main()
{
C test = new C();
_ParentType = test.GetType().BaseType;
method_ptr = _ParentType.BaseType.GetMethod("Test").MethodHandle.GetFunctionPointer();
_GrandparentTest = (Action)Activator.CreateInstance(typeof(Action), test, method_ptr);
_GrandparentTest();
}
public class A {
public virtual void Test()
{
Console.WriteLine("A.Test() called");
}
}
public class B : A {
public override void Test()
{
base.Test();
Console.WriteLine("B.Test() called");
}
}
public class C : B {
public override void Test()
{
base.Test();
Console.WriteLine("C.Test() called");
}
}
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Cheers, I will close. It’s a Unity-specific issue rather than DFU, and you can still update it with more info if needed. Issue won’t go anywhere and can still be linked/searched under closed.
Good find locating issue! I’ll keep this one open and they should (hopefully) fix this in 2019.4.x before the 2019.4 LTS period is completed.
I planned to uptick patch version before 1.0, and will do so sooner if a fix is released for this one.