question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with the new Unity update (Mono Compiler)?

See original GitHub issue

Before 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:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
Interkarmacommented, Sep 2, 2021

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.

1reaction
Interkarmacommented, Aug 24, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The build worked with mono, but failed with IL2CPP.
How to troubleshoot build failures: First, make a blank project with a single blank scene and prove that it builds successfully. If the...
Read more >
Manual: Mono overview
Unity uses a fork of the open source Mono project. Some platforms don't support JIT compilation, so the Mono backend doesn't work on...
Read more >
Download - Stable | Mono
The latest Stable Mono release is: 6.12.0 Stable (6.12.0.199) ... Install this package if you run into trouble making HTTPS connections.
Read more >
Unity script won't update after first successful weaving with ...
I'm using Mono.Cecil to modify assemblies post compilation within Unity (I'm using this implementation of Mono.Cecil). For some reason, if I add ...
Read more >
update F# Compiler in Mono to >= VS 15.5.2 #4143
We are guessing a Unity il2cpp issue, but updating the tools on Windows, made it work. I'm hoping if we update the F#...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found