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.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Bug Possible bug in TMPro_UGUI_Private with m_subTextObjects sizing

Discussion in 'UGUI & TextMesh Pro' started by ivoras, Sep 27, 2020.

  1. ivoras

    ivoras

    Joined:
    May 21, 2020
    Posts:
    62
    I've been receiving an IndexOutOfRange exception in the following code in Awake() in the TMPro class from the title:

    Code (CSharp):
    1.             TMP_SubMeshUI[] subTextObjects = GetComponentsInChildren<TMP_SubMeshUI>();
    2.             if (subTextObjects.Length > 0)
    3.             {
    4.                 for (int i = 0; i < subTextObjects.Length; i++)
    5.                     m_subTextObjects[i + 1] = subTextObjects[i];
    6.             }
    7.  
    It's around line 137 in v2.0.1.

    The problem is that `m_subTextObjects` is declared as:

    Code (CSharp):
    1.         protected TMP_SubMeshUI[] m_subTextObjects = new TMP_SubMeshUI[8];
    2.  
    but the size of subTextObjects is 8, so it ALWAYS overflows the array.

    "Fixing" it by declaring m_subTextObjects to hold 9 elements works, but I don't know why this off-by-one is there in the first place.
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    I recently revised this to make sure the above error will no longer occur and that more than 8 sub text objects can also be supported. This change will be included in the next release of the TMP package which I expect to release sometime this week.
     
  3. ivoras

    ivoras

    Joined:
    May 21, 2020
    Posts:
    62
    Thanks!