Search Unity

TextMesh Pro TryAddCharacters broken in 2018.4.6f1

Discussion in 'UGUI & TextMesh Pro' started by DavidZhongIGG, Aug 13, 2019.

  1. DavidZhongIGG

    DavidZhongIGG

    Joined:
    Apr 30, 2019
    Posts:
    7
    Using TMP_FontAsset.TryAddCharacters function (any overload) results in a NullReferenceException at TMP_FontAsset.cs:1242

    Code (CSharp):
    1. Font font = AssetDatabase.LoadAssetAtPath<Font>("Assets/Common/Fonts/Verdana.ttf");
    2. var fontAsset = TMP_FontAsset.CreateFontAsset(font, 30, 5, GlyphRenderMode.SDFAA, 512, 512, AtlasPopulationMode.Dynamic);
    3. fontAsset.TryAddCharacters("Test");
    This is due to FontEngine.TryAddGlyphsToTexture always returning a Glyph[] of length 1024 no matter how many characters you actually try to add.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Just had a chance to look at this ... Oops!

    I made a change to the FontEngine to reduce potential allocations / array resizing which resulted in this issue. Please make the following change to the TMP_FontAsset.cs file at line 1090 and 1239.

    Code (csharp):
    1.  
    2. // Replace the following line as follows
    3. for (int i = 0; i < glyphs.Length; i++)
    4.  
    5. // With the following line
    6. for (int i = 0; i < glyphs.Length && glyphs[i] != null; i++)
    7.  
    These changes are / will be included in the next release.

    You should make this change in the global package cache for version 1.4.1 and not to the local cached version.

    Please let me know if everything works as expected after this change.

    P.S. Will also be adding a new test to cover these functions.
     
    Last edited: Aug 13, 2019
  3. DavidZhongIGG

    DavidZhongIGG

    Joined:
    Apr 30, 2019
    Posts:
    7
    Hi Stephan,

    I tried the fix and it seems to work.

    Any idea when the next version of Text Mesh Pro will be released?
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I still have a few things to address / add but it is coming soon™. Trying to get a preview out this week if possible.
     
  5. evilock

    evilock

    Joined:
    Sep 19, 2016
    Posts:
    20
    Hi, any update on this? We're having this on 2019.1.12f1 and hacking the package cache isn't really a practical option in our environment.
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Trying to get the next package released as soon as possible. It will include this fix.
     
  7. doraemon213

    doraemon213

    Joined:
    Feb 10, 2013
    Posts:
    5
    I am running into this problem in 1.4.1, Unity version 2018.4.26. Any next safe version of TMPro that we can use and has this fix?
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The latest release of TMP for Unity 2018.4 is version 1.5.3 and version 1.5.4 should be out very soon.