-2

Why can Overriding a a virtual method, but only calling the base method and doing nothing else, cause a change in how a program functions?

For Example:

    public override void OnDeserialize(NetworkReader reader, bool initialState)
    {
        base.OnDeserialize(reader, initialState);
    }

Overriding:

    public virtual void OnDeserialize ( NetworkReader reader, bool initialState );

Causes different outcomes.

In my case a networking Library called UNET does not work.

You can see the minimised test case here, which includes the logs.

Jethro
  • 3,029
  • 3
  • 27
  • 56
  • 5
    Can you describe how it causes different outcomes? Can you provide an [MCVE]? – ProgrammingLlama Mar 10 '18 at 10:15
  • What different outcome it causes? – Chetan Mar 10 '18 at 10:33
  • Just building the test case, as I believe it to surely be a bug? Having the method available causes Unity UNET networking to fail. I intended to submit it to Unity, but wanted to make sure I wasn't missing something about C# and override – Jethro Mar 10 '18 at 10:39
  • Sorry if it's a bad question, I was hoping it was clear and was hoping that the simple answer is "No"? Will update with the test case one i finish minimizing – Jethro Mar 10 '18 at 10:42
  • 1
    Yes... The simple answer is `No`. It doesn't change anything if you are just calling base method from the overridden method. I asked for clarification to understand if you have any different expectations from the code. – Chetan Mar 10 '18 at 11:16
  • @john Sure, I updated the Q, please see the test case - sorry for delay was minimising it. You can see the logs in the repo too. I have a bug in with Unity which can be found here https://fogbugz.unity3d.com/default.asp?1012108_nj3qm5pqjd3av052 – Jethro Mar 10 '18 at 11:41

1 Answers1

0

Function change should not happen if overrides are used as intended, however function changes are still easily possible.

Libraries could use Reflection to determine if a class is overriding a function, and change it's actions dependent on that check.

In this case it seems to be a bug with Unity. I think it checks to see if a method needs to be called, as an optimisation, are incorrectly written, and cause the change in program flow.

Jethro
  • 3,029
  • 3
  • 27
  • 56