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 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!
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.
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.
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:
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:
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:
"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!
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 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