Search Unity

TMPro 2017.1 Array Index out of Range error

Discussion in 'UGUI & TextMesh Pro' started by CDF, Jun 30, 2017.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Started getting a lot of these errors after updating TMPro to 2017.1

    Code (CSharp):
    1. IndexOutOfRangeException: Array index is out of range.
    2. TMPro.TMP_Text.StringToCharArray (System.String sourceText, System.Int32[]& charBuffer)
    3. TMPro.TMP_Text.ParseInputText ()
    4. TMPro.TextMeshProUGUI.OnPreRenderCanvas ()
    5. TMPro.TextMeshProUGUI.Rebuild (CanvasUpdate update)
    6. UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:150)
    7. 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
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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.
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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.
     
    CDF likes this.
  4. ndever

    ndever

    Joined:
    Apr 22, 2017
    Posts:
    15
    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!
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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.
     
  6. ndever

    ndever

    Joined:
    Apr 22, 2017
    Posts:
    15
    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.
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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.
     
  8. ndever

    ndever

    Joined:
    Apr 22, 2017
    Posts:
    15
    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?
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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?
     
  10. ndever

    ndever

    Joined:
    Apr 22, 2017
    Posts:
    15
    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()
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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()?
     
  12. ndever

    ndever

    Joined:
    Apr 22, 2017
    Posts:
    15
    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<TextMeshProUGUI>().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<TextMeshProUGUI>().text = gameObject.GetComponent<CharacterID>().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..
     
  13. samlabs_lea

    samlabs_lea

    Joined:
    May 1, 2018
    Posts:
    7
    We are also seeing this error in our project.
     
  14. ndever

    ndever

    Joined:
    Apr 22, 2017
    Posts:
    15
    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:

    https://docs.microsoft.com/en-us/do...o?redirectedfrom=MSDN&view=netframework-4.7.2
    https://docs.microsoft.com/en-us/do...lization_TextElementEnumerator_GetTextElement
     
    spinaljack and Stephan_B like this.
  15. pabitrapadhy

    pabitrapadhy

    Joined:
    Feb 4, 2017
    Posts:
    6
    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.
     
  16. wiyi

    wiyi

    Joined:
    Feb 20, 2013
    Posts:
    17
    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
     
  17. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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.
     
  18. hippogaga

    hippogaga

    Joined:
    Dec 14, 2018
    Posts:
    1
    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
     
  19. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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 #.
     
  20. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    315
    I seem to be getting the same issue, what's the state on this?
     
  21. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I still need someone to submit a bug report to allow me to reproduce the issue.
     
  22. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    315
    Launching the game tomorrow, but will probably put up a bug once I have some time. If I forget, do feeel free ot ping me again :D
     
  23. spinaljack

    spinaljack

    Joined:
    Mar 18, 2010
    Posts:
    992
    This was my problem, thanks!
    Was scratching my head for days...
     
  24. ajeets1978

    ajeets1978

    Joined:
    Mar 10, 2019
    Posts:
    25
    How to solve this:

    IndexOutOfRangeException: Index was outside the bounds of the array.
    TMPro.TextMeshProUGUI.GenerateTextMesh () (at Assets/Scripts/TMPro/TextMeshProUGUI.cs:967)
    TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at Assets/Scripts/TMPro/TextMeshProUGUI.cs:759)
    TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Assets/Scripts/TMPro/TextMeshProUGUI.cs:2296)
    UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:198)
    UnityEngine.Canvas:SendWillRenderCanvases() (at C:/buildslave/unity/build/Runtime/UI/ScriptBindings/UICanvas.bindings.cs:72)