Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    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

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    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.