Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    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:
    15
    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:
    4,957
    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:
    15
    Thanks!
     
unityunity