Search Unity

TextMeshPro IndexOutOfRangeException

Discussion in 'UGUI & TextMesh Pro' started by pixel_maniacs, Dec 4, 2020.

  1. pixel_maniacs

    pixel_maniacs

    Joined:
    Jun 25, 2015
    Posts:
    71
    I am updating a TMPro Ugui (Version 2.1.3) label and get this exception on a very different component lying in the scene and beeing hidden by an alpha blended canvasGroup?

    Any help how to digg to the root cause is very appreciated. I have absolutley no clue where to begin digging.

    I am looping through different character sets (english, korean, chinese) in a different labeltext causing this to happen.

    https://www.dropbox.com/s/w8fno5094vsujg6/languageCycle.mp4?dl=0

    Code (CSharp):
    1.  
    2. IndexOutOfRangeException: Index was outside the bounds of the array.
    3. TMPro.TMP_Text.FillSpriteVertexBuffers (System.Int32 i, System.Int32 index_X4) (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMP_Text.cs:6819)
    4. TMPro.TextMeshProUGUI.GenerateTextMesh () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMPro_UGUI_Private.cs:3905)
    5. TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMPro_UGUI_Private.cs:1654)
    6. TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TextMeshProUGUI.cs:224)
    7. UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/Program Files/UnityHubInstall/2019.4.1f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/CanvasUpdateRegistry.cs:210)
    8. UnityEngine.Canvas:SendWillRenderCanvases()
    9.  
     
    Last edited: Dec 7, 2020
  2. pixel_maniacs

    pixel_maniacs

    Joined:
    Jun 25, 2015
    Posts:
    71
    It happens on this component, on character 7 which is a sprite.
    Code (CSharp):
    1.  
    2. TMP_Text.cs : Line 6816
    3.  
    4. // i = 7
    5. // index_X4 = 0
    6. protected virtual void FillSpriteVertexBuffers(int i, int index_X4)
    7. {
    8.     int materialIndex = m_textInfo.characterInfo[i].materialReferenceIndex;
    9.     // materialIndex = 2
    10.     // but m_textInfo.meshInfo only has 2 entries => Index Out Of bounds Exception
    11.     // it is a sprite on a different atlas which is configured and works the most time. only oin this constelation it throws an error
    12.     // here should be a check if meshinfo has enough entries to get that, no need for an IndexOutOfBoundsException
    13.     index_X4 = m_textInfo.meshInfo[materialIndex].vertexCount;
    14.  }
    15.  
    16.  
     

    Attached Files:

  3. pixel_maniacs

    pixel_maniacs

    Joined:
    Jun 25, 2015
    Posts:
    71
    Another watch
     

    Attached Files:

  4. WolveX

    WolveX

    Joined:
    May 31, 2016
    Posts:
    49
    I am having the same issue after I update to TMPro (1.5.3) using Unity 2018.4.28f1 (same on Unity 2018.4.30f1)
    Downgrading to TMPro (1.5.1) solved the issue for me, but I would like to keep using the latest version without this issue
     
    pixel_maniacs likes this.
  5. pixel_maniacs

    pixel_maniacs

    Joined:
    Jun 25, 2015
    Posts:
    71
    OK an update, an animation ping ponged the font alpha from zero to 1 and was causing the bug to happen. I do not have any clue what this means
     
  6. WolveX

    WolveX

    Joined:
    May 31, 2016
    Posts:
    49
    @Stephan_B can you help us in this issue please
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I just need someone to submit a bug report with project or whatever is needed for me to be able to reproduce the issue.

    I am working on version 1.5.4 and equivalent release for other unity versions so if I can get this bug report, I can make sure the fix is included in there.
     
    WolveX likes this.
  8. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    515
    On 2.1.3 same stack. Did not investigate further but it's really recent (Main changes is I rebuilded Font-Awesome and updated TMP Pro to 2.1.3
    Code (CSharp):
    1. IndexOutOfRangeException: Index was outside the bounds of the array.
    2. TMPro.TMP_Text.FillSpriteVertexBuffers (System.Int32 i, System.Int32 index_X4) (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMP_Text.cs:6819)
    3. TMPro.TextMeshProUGUI.GenerateTextMesh () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMPro_UGUI_Private.cs:3905)
    4. TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMPro_UGUI_Private.cs:1654)
    5. TMPro.TextMeshProUGUI.UpdateSDFScale (System.Single scaleDelta) (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMPro_UGUI_Private.cs:4585)
    6. TMPro.TextMeshProUGUI.InternalUpdate () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMPro_UGUI_Private.cs:1573)
    7. TMPro.TMP_UpdateManager.DoRebuilds () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMP_UpdateManager.cs:153)
    8. UnityEngine.Canvas.SendWillRenderCanvases () (at <4af5bea1b7b2442494fd73f6f9b3d7f4>:0)
     
    Last edited: Jan 16, 2021
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Please see if making the change outlined in the following post resolves the issue.
     
  10. WolveX

    WolveX

    Joined:
    May 31, 2016
    Posts:
    49
    Hello @Stephan_B,
    Thank you, this change fixed the issue for us.
    But we will keep using the older version until you ship an updated version on Package Manager.
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Glad to know that resolved this issue. This change will be in the next release which I am hoping to have available by the end of the week.
     
    chill_wizard and WolveX like this.
  12. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    515
    on line 1616 did `if (true/*m_isInputParsingRequired || m_isTextTruncated*/)` and the error is indeed gone.
    Thank you very much for the hack.
     
    Stephan_B likes this.
  13. walaber_entertainment

    walaber_entertainment

    Joined:
    Jul 10, 2017
    Posts:
    30
    just wanted to mention we've run into this issue as well. the fix on line 1616 seems to have worked for us, but obviously it's not a great solution, as modifying a package is not something we can easily maintain or even chare properly via source control for our project. Is there an ETA on an update to TMPro in the package manager with this fix implemented? we are very near a submission date on our project.
     
    Paul_H23 and WolveX like this.
  14. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Trying to get this new release out this week.
     
  15. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    45
    I presume this release still hasn't been completed, still showing 2.1.3 in Package Manager? I'm fighting this problem at the moment at a critical point in our release, it's treacherous, as every time I close Unity and re-open it, the hack fix suggested above (here) gets wiped out, making the release process quite risky. Any idea when a fix will be released?
     
    walaber_entertainment likes this.
  16. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    In final testing of these new releases. Unless I run into some unexpected issue, they will be available this week.

    In terms of source code changes, in order to make them persistent, they have to be made in the Global Package Cache.
     
  17. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    45
    I'm guessing you ran into some unexpected issues?
     
  18. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I did but was able to resolve them over the weekend.

    I'll do additional testing tomorrow and if all goes well, will proceed with the release.
     
    Roman-Ilyin, isaac-ashdown and WolveX like this.
  19. Roman-Ilyin

    Roman-Ilyin

    Joined:
    Oct 9, 2013
    Posts:
    29
    Hello. Is there any news about the release date?
     
  20. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Should be available later today.
     
  21. davidosullivan

    davidosullivan

    Joined:
    Jun 9, 2015
    Posts:
    387
    This is still screwed for me. I was fine on 2.0.1. After updating to 2.1.6 I had 999+ errors on literally every TMP object. So I tried downgrading back to 2.0.1 and they went away, then I tried 2.1.0-preview1 and the same again. I havent tried the ones in between. I was only upgrading to try and solve this issue...https://forum.unity.com/threads/mis...s-been-destroyed-but-you-are-still-tr.750500/
    This is in 2019.4.15f1 by the way- but please don't say I need to upgrade to a newer version of Unity because thats a massive load of work in itself...
     
  22. davidosullivan

    davidosullivan

    Joined:
    Jun 9, 2015
    Posts:
    387
    Update: I tried manually updating 2.0.1 TMP_Dropdown.cs ->OnDisable() by adding base.OnDisable() _at the top of the method_, and BOOM all the same errors again. then I tried adding base.OnDisable() _at the end_ of the method and PEACHY, no 'TMP_Dropdown' has been destroyed errors and no TextMeshPro IndexOutOfRangeException errors either, so is this the right solution?
     
  23. LandePlage

    LandePlage

    Joined:
    May 21, 2016
    Posts:
    33
    I'm getting this error when changing the "Overflow" to anything other than "Overflow", in the text inside an input field.
    Seems to have something to do with caret calculation.

     
  24. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Could you please submit a bug report with project and steps to reproduce?

    If you do submit a bug report, please provide the case # once you have it.
     
  25. LandePlage

    LandePlage

    Joined:
    May 21, 2016
    Posts:
    33
    A while after posting this, I realized I was using a non-standard setup where I was using two text objects inside the input field.

    Reverting back to just one works, so I think we can disregard this issue.