Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug (2020 LTS version) Editor glitches out after code execution in game

Discussion in 'Editor & General Support' started by DaoSoul, May 30, 2021.

  1. DaoSoul

    DaoSoul

    Joined:
    Oct 23, 2016
    Posts:
    2
    After executing the following code the inspector/hierarchy/projec/console tabs become black and glitched and effectively unusable until restarted.

    Code (CSharp):
    1. SpriteRenderer sr = this.GetComponent<SpriteRenderer>();
    2.  
    3.         Texture2D tex = Texture2D.whiteTexture;
    4.         tex.Resize(100, 100);
    5.  
    6.         sr.sprite = Sprite.Create(tex, new Rect(0, 0, 100, 100), new Vector2(0.5f, 0.5f));
    Inspector afterwards:


    The following code does not cause this:

    Code (CSharp):
    1. SpriteRenderer sr = this.GetComponent<SpriteRenderer>();
    2.  
    3.         Texture2D tex = Texture2D.whiteTexture;
    4.         //tex.Resize(100, 100);
    5.  
    6.         sr.sprite = Sprite.Create(tex, new Rect(0, 0, 4, 4), new Vector2(0.5f, 0.5f));
     
  2. DaoSoul

    DaoSoul

    Joined:
    Oct 23, 2016
    Posts:
    2
    After some further research, with this you can basically color in the Editor UI, probably because it does not check for creating a new tex and instead just accesses the other default textures and you can overwrite their colour and everything. Basically, texture is not properly encapsulated. I am not sure, but it could be a big security issue
     
    Last edited: May 30, 2021