Search Unity

Bug TMP_Text.CalculatePreferredValues Breaks Under Specific Circumstances

Discussion in 'UGUI & TextMesh Pro' started by MiyukiNinja, Jun 15, 2022.

  1. MiyukiNinja

    MiyukiNinja

    Joined:
    Dec 20, 2017
    Posts:
    7
    When creating a chain of two or more TextMeshPro - Text (UI) components, with the Overflow setting on Linked for all but the final one, calling LayoutUtility.GetPreferredHeight(x) where x is the RectTransform for this final component fails to compute the correct value if there are two or more New Line (\n) commands inbetween the last visible character of the penultimate text component and the first visible character of the final text component. I am using TMPro version 3.0.6, and Unity version 2022.1.1f1.

    I tracked this bug as far as TMP_Text.CalculatePreferredValues, more specifically to within the for loop beginning for (int i = 0; i < m_TextProcessingArray.Length && m_TextProcessingArray.unicode != 0; i++) on line 4051 of TMP_Text.cs, under the heading comment "Parse through Character buffer to read HTML tags and begin creating mesh." and it appears that a number of variables are set to the values for TMP_Math's FLOAT_MAX/FLOAT_MIN/FLOAT_UNSET/INT_UNSET during this loop at some point while parsing the new lines, causing the end result to be off by about -2^16.
     
    Last edited: Jun 15, 2022
  2. MiyukiNinja

    MiyukiNinja

    Joined:
    Dec 20, 2017
    Posts:
    7
    It seems the text containing the new lines also has to be set on the same frame for this to occur, and I have submitted a proper bug report.