Runtime errors with virtual methods on android but not in editor (2019.3)

Hi,

We’ve run into an interesting issue in Unity 2019.3. When building for Android with IL2CPP, calling the overridden virtual method of an abstract class somehow causes the virtual base method to get called rather than the override method.

As an example, with the abstract base class Piece and implementation BasicPiece:

public abstract class Piece
{
    // ...

    public virtual Piece GetCopy()
    {
        throw new NotImplementedException();
    }
}

public class BasicPiece : Piece
{
    // ...

    public override Piece GetCopy()
    {
        return new BasicPiece(Visual, _pieceColor);
    }
}

The code above results in the following runtime error, on Android only:

2020-03-09 15:12:12.343 24791-24839/? E/Unity: NotImplementedException: The method or operation is not implemented.
at Piece.GetCopy () [0x00000] in <00000000000000000000000000000000>:0
...

Now, initially I thought this had to be a code mistake on our part. Surely GetCopy() isn’t actually getting overridden and we’re accidentally calling the base type. To verify, we replaced the virtual modifier on GetCopy() with abstract, like so:

public abstract class Piece
{
    // ...

    public abstract Piece GetCopy();
}

To our confusion, this version runs perfectly fine on Android with no runtime errors. No other changes were made.
Is there any chance we’re missing something simple here or did we maybe stumble into a new regression in IL2CPP?

Probably worth adding, this same code ran fine when compiled for Android using Unity 2019.2.

Okay, so, situation update. It seems all but confirmed that this is some kind of a compilation bug.

  1. Running in Unity editor works.
  2. Running in Android, development build, causes a runtime error.
  3. Running in Android, development build, script debugging enabled works.

We’re working on stripping down a minimal project to reproduce this. In the meanwhile, is such a bug already known and if so, are there any known workarounds?

My first thought is il2cpp cache. Try deleting it (under Library folder).

Hi, thank you for the response. I’m assuming the il2cpp_android_xxx folders are the caches? Unfortunately deleting these and letting them regenerate on build didn’t help, the runtime errors are still happening.

Please, report a bug.