Search Unity

Bug With Getutf32 Conversion

Discussion in 'UGUI & TextMesh Pro' started by Rafael_CS, Apr 11, 2019.

  1. Rafael_CS

    Rafael_CS

    Joined:
    Sep 16, 2013
    Posts:
    162
    Hello, i found a bug in method below (inside script TMP_Text.cs)

    The conversion of the last character of UTF32 is incorrect.
    Values converted using

    protected int GetUTF32(string text, int i)
    {
    int unicode = 0;
    unicode += HexToInt(text) << 30; //Change this value to 28 to correct this
    unicode += HexToInt(text[i + 1]) << 24;
    unicode += HexToInt(text[i + 2]) << 20;
    unicode += HexToInt(text[i + 3]) << 16;
    unicode += HexToInt(text[i + 4]) << 12;
    unicode += HexToInt(text[i + 5]) << 8;
    unicode += HexToInt(text[i + 6]) << 4;
    unicode += HexToInt(text[i + 7]);
    return unicode;
    }

    the method used by the screenshot below (TMP_TextUtilities.StringToInt(text)) will convert the value

    Hex: 2665fe0f
    Int: 644218383

    upload_2019-4-10_21-7-37.png

    But when typing \U2665fe0f the value converted to int is -2147483647 because of the incorrect conversion in GetUTF32 of TMP_Text.

    Just change de <<30 to 28 to fix the problem (or use TMP_TextUtilities.StringToInt(text))

    Best Regards
    Rafael
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Thank you for reporting the issue.

    Not sure how that managed to remain unreported for so long :eek:
     
    Rafael_CS likes this.