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 Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Bug IndexOutOfBoundsException when using <u> or <mark> with vertices count bigger than 65535

Discussion in 'UGUI & TextMesh Pro' started by falko17, Jun 11, 2021.

  1. falko17

    falko17

    Joined:
    Jun 11, 2021
    Posts:
    1
    Creating a TextMeshPro with enough text together with underlines (<u>) will eventually cause an IndexOutOfBoundsException in the file TMP_Text.cs in the method
    DrawUnderlineMesh
    at line 5750, because
    vertices[index]
    is accessed while
    index > m_textInfo.meshInfo[underlineMaterialIndex].vertices.Length
    .
    This causes an exception in the log, as well as the underlines and/or highlights not to appear in the TextMeshPro.

    This only happens if the vertices array has a length of 65532 before new meshes are added. In this case, the
    ResizeMeshInfo
    method in file
    TMP_MeshInfo.cs
    , which gets called to allocate a larger buffer, sets the target size to
    Mathf.Min(size, 16383)
    . There's some commented out code above this:
    Code (CSharp):
    1. // If the requested size will exceed the 16 bit mesh limit, switch mesh to use 32 bit.
    2. //if (size > 16383 && this.mesh.indexFormat == IndexFormat.UInt16)
    3. //    this.mesh.indexFormat = IndexFormat.UInt32;
    4.  
    Here's a screenshot of the exception when too many <mark> tags are used:

    The exception thrown here comes from the method DrawTextHighlight and follows the same pattern as described above, i.e. the vertices array has length 65532, the same
    ResizeMeshInfo
    method is called, then the IndexOutOfBoundsException in the screenshot occurs.
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    This is indeed a known limitation / issue which I need to address at some point.

    Until then, I would recommend trying to split up the text object in multiple smaller ones. This would also be more efficient as most of the time a lot of the characters in this large object are not visible.
     
    falko17 likes this.