TMPro 2017.1 Array Index out of Range error

Started getting a lot of these errors after updating TMPro to 2017.1

IndexOutOfRangeException: Array index is out of range.
TMPro.TMP_Text.StringToCharArray (System.String sourceText, System.Int32[]& charBuffer)
TMPro.TMP_Text.ParseInputText ()
TMPro.TextMeshProUGUI.OnPreRenderCanvas ()
TMPro.TextMeshProUGUI.Rebuild (CanvasUpdate update)
UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:150)
UnityEngine.Canvas:SendWillRenderCanvases()

Can’t seem to nail it down, but generally happens after a recompile and turning on inactive parent containers. Pressing play fixes the issue temporarily

Issue was reported by a few users on the TMP user forum. Already have a fix for it which will be included in the next release which I am hoping to have available next week.

I uploaded a new release of TextMesh Pro for 2017.1 which includes a fix for the issue you have reported.

Please give the following package a try and let me know if it resolves your issue. The link to the package is in the TextMesh Pro sticky post.

1 Like

Hi,

I started having this error using the newest version of Unity (2018.2.9f1) and TextMeshPro (1.2.4). It seems that the error occurs when I want to display UTF-32 characters e.g or . The strange thing is Unity can display them at first but then on a different object I get the error. Any help would be appreciated!

What character are you trying to display?

Is this character included in your Primary font asset (assigned to the text object)?

If not, is this character included in any of the fallback font assets assigned to the primary?

Or is this character included in any of the font assets assigned in the general fallback in the TMP Settings?

Is this character / unicode contained in the sprite asset or any fallback sprite assets?

Make sure you do not have any circular references in your fallback font assets or any empty entries in the fallback font assets list of these font asset or in the TMP Settings fallback list.

Thanks for the quick response.

With \u00020089 character I get the error for example.

It is included in a fallback font asset assigned to the primary.

It is contained in the fallback sprite asset - if I get this question right.

I have only one fallback font asset in the list and no empty entries.

The character displays without any problem on one game object but throws an error every time with another.

The format for UTF16 in C# is “\u00FF” or lowercase \u with 2 hexadecimal pairs.

The format for UTF32 in C# is “\U00FF00FF” or upper case \U with 4 hexadecimal pairs.

As such \u00020089 will try to display \u0002 followed by 0089. Most likely you do not have a character using unicode 0002 in there.

I use a csv file with the characters not their UTF codes. I only used UTF code in the comment because this forum won’t recognise the character if I just copy and paste it.

As I said this character works just fine on one game object and won’t work for another.

Am I missing something?

Are both text object using the same font asset? Is there anything different about these two text objects?

Can you provide a simple repro of this?

They are using the exact same font asset. Both objects are components of two different prefabs instantiated at runtime. They both get their characters from the same list and I checked, they do get them. There shouldn’t be any difference between the two text objects except one displays 6 characters and the faulty one just 1.

I tried to work out a simple repro but couldn’t do it. If I just put several of these prefabs on the canvas with the mentioned character it works just fine. I’m gonna try some things on the weekend e.g. make a new prefab, generate a new font asset or using other methods to display the characters. Until then do you have any advice where should I start looking?

By the way, this is the whole error message:

IndexOutOfRangeException: Index was outside the bounds of the array.
TMPro.TMP_Text.StringToCharArray (System.String sourceText, System.Int32[ ]& charBuffer) (at //AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.textmeshpro@1.2.4/Scripts/Runtime/TMP_Text.cs:2339)
TMPro.TMP_Text.ParseInputText () (at //AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.textmeshpro@1.2.4/Scripts/Runtime/TMP_Text.cs:1688)
TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at //AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.textmeshpro@1.2.4/Scripts/Runtime/TMPro_UGUI_Private.cs:1622)
TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at //AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.textmeshpro@1.2.4/Scripts/Runtime/TextMeshProUGUI.cs:209)
UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:150)
UnityEngine.Canvas:SendWillRenderCanvases()

Depending on the size of the project, it might be easier for you to simply submit a bug report with a clear description of how to reproduce the behavior.

I’ll be more than happy to take a look at it to figure out what is the cause of this issue.

Outside of getting the project or some repro, my advice would be to carefully examine the text being provided to each text object. Ie. iterate over each string in debug mode to make 100% sure they are exactly the same.

How are you setting the text on these objects? Are you using the .text property or SetText()?

I use .text property but tried with SetText() and it is all the same.

I did some further investigation and maybe the difference I mentioned earlier has something to do with the error. One gameobject displays six of these characters and gets them by:

object1.transform.Find(“Text”).GetComponent().text = String.Join(“”, CharacterList*.*Characters)

This works just fine every time with every character chain. The other gameobject selects a random (0-5) element of the list containing 6 characters and displays only that:

object2.transform.Find(“Text”).GetComponent().text = gameObject.GetComponent().Characters[random].ToString()

With this, I get the error. I managed to get a new error message. Writing the character to console gives me this:

Error: UTF-16 to UTF-8 conversion failed because the input string is invalid

It seems that if the problem is somehow getting that exact element of the list. But here, I am lost…

We are also seeing this error in our project.

Ok, so finally figured out the problem and it is not TextMeshPro related - hence the other error with Debug.Log. I read many forum topics, this was the most helpful:

https://stackoverflow.com/questions/6801397/how-do-i-use-32-bit-unicode-characters-in-c

"But there is nothing special you need to do to to work with characters that don’t fit into one 16-bit char, unless you do string manipulation. They will just be represented as surrogate pairs, but you shouldn’t need to know about that if you treat the string as a whole.
One exception is that some string manipulation methods won’t work correctly. For example “\U0001F4A9”.Substring(1) will return the second half of the surrogate pair, which is not a valid string." → I tried to do something like this.

Solution: now I manage these characters in a string array, each string is a character (surrogate pair if that’s the case) and the error is gone. Hope this helps others!

Some other useful links in this topic:

2 Likes

I am facing a different issue.

I have found the steps to reproduce the error, after debugging.
Before the scene is loaded, hover your mouse over the text mesh pro box.
It will throw that array out of bounds error.
It’s 100% reproducible.

I am using Unity 2018.2 with the TMP embedded in Unity.

IndexOutOfRangeException: Index was outside the bounds of the array.
TMPro.TMP_InputField.GenerateCaret (UnityEngine.UI.VertexHelper vbo, UnityEngine.Vector2 roundingOffset) (at Library/PackageCache/com.unity.textmeshpro@1.4.0/Scripts/Runtime/TMP_InputField.cs:3304)
TMPro.TMP_InputField.OnFillVBO (UnityEngine.Mesh vbo) (at Library/PackageCache/com.unity.textmeshpro@1.4.0/Scripts/Runtime/TMP_InputField.cs:3271)
TMPro.TMP_InputField.UpdateGeometry () (at Library/PackageCache/com.unity.textmeshpro@1.4.0/Scripts/Runtime/TMP_InputField.cs:3209)
TMPro.TMP_InputField.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro@1.4.0/Scripts/Runtime/TMP_InputField.cs:3184)
UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:198)
UnityEngine.Canvas:SendWillRenderCanvases()

unity 2018.3.8f1 dynamic font input component

Can you please submit a bug report with the included project so I can take a look at it?

Also give this a try using version 1.4.1-preview.1 of TMP.

IndexOutOfRangeException: Index was outside the bounds of the array.
TMPro.TMP_InputField.GenerateCaret (UnityEngine.UI.VertexHelper vbo, UnityEngine.Vector2 roundingOffset) (at New Unity Project/Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMP_InputField.cs:3304)
TMPro.TMP_InputField.OnFillVBO (UnityEngine.Mesh vbo) (at New Unity Project/Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMP_InputField.cs:3271)
TMPro.TMP_InputField.UpdateGeometry () (at New Unity Project/Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMP_InputField.cs:3209)
TMPro.TMP_InputField.Rebuild (UnityEngine.UI.CanvasUpdate update) (at New Unity Project/Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMP_InputField.cs:3184)
UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:198)
UnityEngine.Canvas:SendWillRenderCanvases()

When I input Chinese Characters in Unity editor
Unity 2019.1.0f2

Please submit a bug report and include the project. This will enable me to figure out exactly why this issue is occuring.

Once you have submitted the bug report. Please provide me with the Case #.

I seem to be getting the same issue, what’s the state on this?