Search Unity

Webplayer Inheritance Bug

Discussion in 'Scripting' started by guavaman, Jul 9, 2014.

  1. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    I filed this bug report today. Just reposting here in case anyone else runs into it.

    Webplayer throws an exception when a class inherits from a base class and defines a protected child class which inherits from a protected child of the base class and the constructor is called. This only affects Webplayer (editor and build).

    Tested in 4.5.1f3

    Error:
    MethodAccessException: Error verifying InhertianceBug/Element_Broken/DataSet/Data:.ctor (): Method InhertianceBug/Element_Base_Broken/DataSet_Base/Data_Base:.ctor () is not accessible at 0x0001

    Bug Case:
    618671

    Workaround:
    Child classes must be declared internal or public instead of protected.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. public class InhertianceBug : MonoBehaviour {
    5.   protected Element_Broken element_broken_protected;
    6.   protected Element_Works element_works_public;
    7.   void Awake() {
    8.   // Run in the editor in Webplayer mode.
    9.   // Uncomment this to see the crash:
    10.   // MethodAccessException: Error verifying InhertianceBug/Element_Broken/DataSet/Data:.ctor ():
    11.   // Method InhertianceBug/Element_Base_Broken/DataSet_Base/Data_Base:.ctor () is not accessible at 0x0001
    12.   element_broken_protected = new Element_Broken();
    13.   // Comment the above and uncomment this line to see this version that doesn't crash in webplayer
    14.   //element_works_public = new Element_Works();
    15.   }
    16.   #region Broken -- Uses protected on DataSet and DataSet_Base
    17.   public abstract class Element_Base_Broken {
    18.   protected DataSet_Base dataSet;
    19.   public Element_Base_Broken() {}
    20.   protected abstract class DataSet_Base {
    21.   protected Data_Base data;
    22.   public DataSet_Base() {
    23.  
    24.   }
    25.   public abstract class Data_Base {
    26.   public Data_Base() { }
    27.   }
    28.   }
    29.   }
    30.   public class Element_Broken : Element_Base_Broken {
    31.   public Element_Broken() : base() {
    32.   dataSet = new DataSet();
    33.   }
    34.   protected class DataSet : DataSet_Base {
    35.   public DataSet(): base() {
    36.   data = new Data();
    37.   }
    38.   public class Data : Data_Base {
    39.   public Data() : base() { }
    40.   }
    41.   }
    42.   }
    43.   #endregion
    44.   #region Works -- Uses public on DataSet and DataSet_Base
    45.   public abstract class Element_Base_Works {
    46.   protected DataSet_Base dataSet;
    47.   public Element_Base_Works() { }
    48.   public abstract class DataSet_Base {
    49.   protected Data_Base data;
    50.   public DataSet_Base() {
    51.   }
    52.   public abstract class Data_Base {
    53.   public Data_Base() { }
    54.   }
    55.   }
    56.   }
    57.   public class Element_Works : Element_Base_Works {
    58.   public Element_Works()
    59.   : base() {
    60.   dataSet = new DataSet();
    61.   }
    62.   public class DataSet : DataSet_Base {
    63.   public DataSet()
    64.   : base() {
    65.   data = new Data();
    66.   }
    67.   public class Data : Data_Base {
    68.   public Data() : base() { }
    69.   }
    70.   }
    71.   }
    72.   #endregion
    73.  
    74. }
    75.  
     
    Last edited: Jul 16, 2015
  2. _Paulius

    _Paulius

    Mobile Developer Unity Technologies

    Joined:
    Jul 8, 2014
    Posts:
    173
    Hi,

    Thank you for reporting this issue, our developers are already investigating it.

    Regards,
    Paulius QA Team
     
  3. UraniumSlug

    UraniumSlug

    Joined:
    Apr 5, 2013
    Posts:
    5
    I also ran into this today, only in web player. I have a relatively complicated hierarchy of my own classes, but all were declared public.
     
  4. nhimmisha

    nhimmisha

    Joined:
    Nov 26, 2013
    Posts:
    5
    Did this error get fixed? I'm still getting it in 4.6.3f1 - webplayer
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    The case shows as Open so I guess not.