Using TMP_FontAsset.TryAddCharacters function (any overload) results in a NullReferenceException at TMP_FontAsset.cs:1242
Font font = AssetDatabase.LoadAssetAtPath<Font>("Assets/Common/Fonts/Verdana.ttf");
var fontAsset = TMP_FontAsset.CreateFontAsset(font, 30, 5, GlyphRenderMode.SDFAA, 512, 512, AtlasPopulationMode.Dynamic);
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.
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.
// Replace the following line as follows
for (int i = 0; i < glyphs.Length; i++)
// With the following line
for (int i = 0; i < glyphs.Length && glyphs[i] != null; i++)
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.
Hi Stephan,
I tried the fix and it seems to work.
Any idea when the next version of Text Mesh Pro will be released?
I still have a few things to address / add but it is coming soon™. Trying to get a preview out this week if possible.
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.
Trying to get the next package released as soon as possible. It will include this fix.
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?
The latest release of TMP for Unity 2018.4 is version 1.5.3 and version 1.5.4 should be out very soon.