Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

IndexOutOfRangeException in FillSpriteVertexBuffers

Discussion in 'UGUI & TextMesh Pro' started by laessnb, Nov 19, 2020.

  1. laessnb

    laessnb

    Joined:
    Jun 10, 2014
    Posts:
    93
    I had a null reference in TMPro that I thought was Editor-only, so I decided to postpone looking into it, but it just popped up in a standalone build.

    Callstack:

    IndexOutOfRangeException: Index was outside the bounds of the array.
    at TMPro.TMP_Text.FillSpriteVertexBuffers (System.Int32 i, System.Int32 index_X4) [0x00017] in <ffe6991d8ff94aa89c869994eb65ae17>:0
    at TMPro.TextMeshProUGUI.GenerateTextMesh () [0x05756] in <ffe6991d8ff94aa89c869994eb65ae17>:0
    at TMPro.TextMeshProUGUI.OnPreRenderCanvas () [0x0012c] in <ffe6991d8ff94aa89c869994eb65ae17>:0
    at TMPro.TextMeshProUGUI.ForceMeshUpdate (System.Boolean ignoreActiveState, System.Boolean forceTextReparsing) [0x0003a] in <ffe6991d8ff94aa89c869994eb65ae17>:0
    at TeletypeTMPro+<TeletypeSequence>d__26.MoveNext () [0x000f4] in <d9cd6f83201849859074223644d8dfb6>:0
    at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00026] in <e3cc0d511c49480aba0b4b05faed2ad3>:0

    The code in TMP_Text.cs that causes it, with an out of bounds materialIndex:

    Code (CSharp):
    1. int materialIndex = m_textInfo.characterInfo[i].materialReferenceIndex;
    2. index_X4 = m_textInfo.meshInfo[materialIndex].vertexCount;
    The way I am able to get it to reproduce consistently in my project (which is uploaded to Unity per our other thread, Stephan) is to go into prefab mode on UI tooltip - item, then click on something like item primary stats in the hierarchy and change its font material's face color. Lots of other things trigger it as well. I added some bounds-checking to that area of TMP_Text.cs (as well as to the two other places in that file with similar code), and I get messages that look like this, after materialIndex is obtained:

    materialIndex 3 but only have 3 mesh infos

    I am seemingly able to suppress this, but I'm not sure if there's something wrong with my prefab itself that I should also fix. Thank you.
     
    Last edited: Nov 24, 2020
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,265
    I will try taking a look tomorrow / over the weekend.

    Do you have a Case # for the project you uploaded?
     
  3. laessnb

    laessnb

    Joined:
    Jun 10, 2014
    Posts:
    93
    Yes, it's 1289715. I haven't seen this exception since adding the extra code to TMP_Text, and I'm unable to see any new visual glitches with the relevant labels (but it's hard to know if I broke something in the prefab).
     
  4. Shi_vy

    Shi_vy

    Joined:
    Jan 16, 2019
    Posts:
    1
    I am also having this issue. Only on Android, however. I can't reproduce it in Editor and it doesn't seem to actually break anything.
     
  5. ScottAdams

    ScottAdams

    Joined:
    Nov 23, 2016
    Posts:
    55
    We are having similar issue on WebGL builds
     
  6. Ghetaldus

    Ghetaldus

    Joined:
    Jul 15, 2017
    Posts:
    39
    Just updated TextMeshPro from 2.1.1 to 2.1.3 and I am now getting this as well.
    Android build. Error is showing up in editor. Unity version is 2019.4.16f1.
    upload_2020-12-5_13-13-28.png
     
  7. Ghetaldus

    Ghetaldus

    Joined:
    Jul 15, 2017
    Posts:
    39
    Reverting back TextMeshPro to 2.1.1 got rid of error, so it seems that something is wrong in 2.1.3.
     
  8. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,265
    Are you able to reliably reproduce this error?

    Can you submit a bug report with project so I can take a closer look?
     
  9. RudyTheDev

    RudyTheDev

    Joined:
    Nov 26, 2012
    Posts:
    5
    This happens to me when I manually call
    TextMeshProUGUI.ForceMeshUpdate(true)
    ; because I need to know the size of the text element size so that I can arrange them. (Otherwise, there is a frame delay and the UI "jumps" around and embedded sprites flicker.) 2020.1.15f1, 3.0.3. Did not happen on 3.0.1. Sorry I cannot upload the full project or provide more details at the moment, just leaving a comment in case it helps somehow.
     
  10. Calixte

    Calixte

    Joined:
    Nov 18, 2020
    Posts:
    1
    Same here, I get the same error.

    My game is a card game where you can construct Robots on a hex-based battleground, when you confirm the construction everything goes well but at the end I get the error referring to below line in the TMPro code :

    index_X4 = m_textInfo.meshInfo[materialIndex].vertexCount;

    My Robots cards have a "special ability" text where I refer to a sprite sheet, for instance : "+2 <sprite=5> for each attack suffured."

    Strange thing is that:
    • If I remove the "<sprite=5>" part, error is not firing anymore
    • BUT, other Robots have this in their ability description and fire no errors when constructed.
    • This only happens to certain Robots with no common elements between them and do not happens to some others.
    • I couldn't get a specific part of the code where the error fires, seems like it fires ONLY when everything has been executed, hence absolutely nothing goes wrong in the game.
    • All Robots are built around the same Class with different statistics.
    • Only think I could find linking the "bugging Robots" is that they have an ID (e.g. "DF002") to be identified, which I can use during fights executions to apply their special abilities (e.g. if (robotID == "DF002" then (...) else (execute fight normally) BUT these lines of code has zero interactions with the construction code.
    I am up to help on solving this bug if required !
     
  11. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,265
    I just need one volunteer to submit a bug report with project and the steps for me to reproduce and I should be able to quickly resolve this. The current challenge on my end is simply reproducing the conditions that lead to this error.
     
  12. RudyTheDev

    RudyTheDev

    Joined:
    Nov 26, 2012
    Posts:
    5
    I tried to make a repro project, but I no longer see this error. I have no idea how to reproduce it now. Originally, all I did was update the TMP package from 3.0.1. to 3.0.3 and run the game in editor without doing anything else. I can only imagine something in Unity itself got "stuck". I have since upgraded to 2020.1.17f1 and reimported and rebuilt a bunch of times. I tried downgrading and running various combinations of versions, but no luck.
     
  13. laessnb

    laessnb

    Joined:
    Jun 10, 2014
    Posts:
    93
    Were you not able to open the project I submitted two months ago? I gave you a case # and all that.
     
  14. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,265
    I recall that case with respect to the Editor only serialized data issue but not as it relates to this topic.

    I will pull up this case and take a look later today and follow up once I have more information.
     
  15. laessnb

    laessnb

    Joined:
    Jun 10, 2014
    Posts:
    93
    Hi Stephan, the case # was for a different bug, but the nullref that made me start this thread in the first place was definitely not Editor-only.
     
  16. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,265
    Looks like the project was uploaded afterwards and not contained in the bug report itself. Since the project was uploaded to some internal Unity share, I have requested access to it and awaiting a reply.

    On the other hand, if you can provide me the project via link in private message that is fine as well.
     
  17. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    322
    We're getting this as well with 1.5.3 and I just confirmed that it does not happen with TMP 1.5.1 in Unity 2018.4.30f1. I can reliably reproduce it in Editor Play Mode and on Android when displaying text that uses a sprite from one sprite sheet and then later displaying text that has sprites from a different sprite sheet. These are two different TextMeshPro GameObjects. The sprite sheets also happen to use a different shader, which might affect this. Here's the text in the two GameObjects:

    "The <style=important>scissors <sprite name="cut_os" tint=1></style> move can cut any white edge"

    "Cut an edge to mix <sprite name="ball_os" color=#FEFF00> and <sprite name="ball_os" color=#559CFF>"

    So the "cut_os" sprite is on one sheet and "ball_os" is on a different sheet. If I display either of these texts alone then the exception does not happen. But when I display one and then display the other (order doesn't matter), the materialIndex exception happens.

    The exception does not appear to cause any noticeable rendering or visual problems on-screen, which is strange.

    I tried my best to reproduce this scenario in a separate example scene, but the exception didn't happen. So I'm not sure what conditions exist in our game that don't exist in the sample scene. The obvious setup with the two text objects and the exact same text with two sprite sheets and materials didn't reproduce the problem. Same fallback sprite sheets. Same fonts. I even wrote a script to toggle visibility and resized the UGUI objects with no exception.

    @Stephan_B Hope this information helps you track it down.
     
  18. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,265
    Please see if making the change outlined in the following post resolves the issue.
     
  19. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    322
    I can confirm that this change, when made to version 1.5.3, does stop the exceptions with Unity 2018.4.30f1.
     
  20. isaac-ashdown

    isaac-ashdown

    Joined:
    Jan 30, 2019
    Posts:
    69
    I've been lurking here a while - we've been seeing this exception via the Unity Cloud Diagnostics reports in our live build - we don't get it in the editor though and haven't really found a repro other than "play the game". I tried out your fix, unfortunately we're still seeing the same reports coming from builds that include that change. We're using Unity 2019.4.16f1 and TMP 2.1.3.

    The exception itself doesn't appear to have any noticable impact. However, we have had reports of some users seeing a single-frame flash of our TMP Sprite Atlas texture randomly happen. We have two TMP Sprite Atlases, both in our Resources folder and referenced that way. I thought perhaps it's related to the exception.
     
  21. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,265
    Are you able to reliably reproduce this issue? If so, please submit a bug report with project and steps so I can take a closer look.
     
  22. isaac-ashdown

    isaac-ashdown

    Joined:
    Jan 30, 2019
    Posts:
    69
    No unfortunately - as mentioned, the only repro we have is "play the game in the player, not editor".
    The game is out though and I can send you a development build via steam if you'd like to investigate.
     
  23. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,265
    The behavior you describe is identical to the others so I am surprised the above change didn't resolve this. So please make sure you made the changes in the Global Package Cache otherwise, the change will get reverted.

    If you did make it in the global package cache, then this is likely some other issue specific to sprite asset and your setup where we need to figure how to reproduce it.

    In terms of the flash, do you know when it occurs? On scene load / screen size change / ie. could we narrow this down to some specific event / time.

    Do you know if this happens on any device or perhaps a specific device? Again just trying to narrow this down so we can figure out where to look.
     
  24. isaac-ashdown

    isaac-ashdown

    Joined:
    Jan 30, 2019
    Posts:
    69
    I made the change by copying the package into my Assets folder and removing the package from the package list, and then modifying the code in there. I'm not sure where the global package cache is - I need to have this change in my source control so that the build machine gets it etc. Let me know if there's a better way to do this.

    As for the flash, it happens randomly during gameplay, not during any of those events unfortunately. I haven't been able to repro it on my machine so it seems to be hardware-specific.
     
  25. isaac-ashdown

    isaac-ashdown

    Joined:
    Jan 30, 2019
    Posts:
    69
  26. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,265
    Do you have any text object or something that covers the entire screen? Like you said, this flash is the entire atlas texture taking the whole screen. That seems like some graphic / rendering issue.

    Is there anything special going on at that particular moment?
     
  27. ScottAdams

    ScottAdams

    Joined:
    Nov 23, 2016
    Posts:
    55
    I am looking for the suggested change but do not see it.

    We have this sporadically in our game and was always occurring at the same time. Just when Doom mode started.

    Now instead of the TMP exception we are seeing out of memory errors in WebGL. Eventually I think the Playerloop is causing the memory failure.

    Browser Log snippet follows:


    15:57:20.233 180d3779-496e-402c-a098-e8862bd29549:8 (324.36/335.5418/3d7af/CountDownTextDoom.100) DoomCountDownNoise called

    15:57:20.330 180d3779-496e-402c-a098-e8862bd29549:8 (324.46/335.6418/3d7af/DeathSound.65) PlayAnim: 'AsteroidExplosion'

    15:57:20.330 180d3779-496e-402c-a098-e8862bd29549:8 (324.46/335.6418/3d7af/SpaceObject.1159) Destroying spaceObjectId 372 DoomMode: False

    15:57:20.332 180d3779-496e-402c-a098-e8862bd29549:8 (324.46/335.6418/3d7af/DeathSound.76) Playing animation: 'AsteroidExplosion'

    15:57:20.482 180d3779-496e-402c-a098-e8862bd29549:8 (324.62/335.8018/3d7af/SpaceObject.1710) Revealing and activating previously hidden ship 125

    15:57:21.246 180d3779-496e-402c-a098-e8862bd29549:8 (325.38/336.5618/3d7b0/CountDownTextDoom.140) DestroyCountdownObject called

    15:57:21.276 180d3779-496e-402c-a098-e8862bd29549:8 (325.4/336.5818/3d7b0/CountDownTextDoom.100) DoomCountDownNoise called

    15:57:21.276 180d3779-496e-402c-a098-e8862bd29549:8 (325.4/336.5818/3d7b0/CountDownTextDoom.122) DoomNoise called

    15:57:21.332 UnityLoader.js:4 exception thrown: RuntimeError: memory access out of bounds,RuntimeError: memory access out of bounds
    at <anonymous>:wasm-function[9027]:0x38f5fb
    at <anonymous>:wasm-function[14465]:0x5edf95
    at <anonymous>:wasm-function[62212]:0x13975ae
    at <anonymous>:wasm-function[62211]:0x139755e
    at <anonymous>:wasm-function[40240]:0xf11f3f
    at <anonymous>:wasm-function[32974]:0xd6ff04
    at <anonymous>:wasm-function[40238]:0xf0a934
    at <anonymous>:wasm-function[40273]:0xf193aa
    at <anonymous>:wasm-function[32397]:0xd4df1e
    at <anonymous>:wasm-function[40118]:0xf02ba0
    at <anonymous>:wasm-function[37538]:0xe7f4f8
    at <anonymous>:wasm-function[78360]:0x177abea
    at <anonymous>:wasm-function[29954]:0xd13b7a
    at dynCall_iiiii (<anonymous>:wasm-function[82469]:0x1877f00)
    at Object.dynCall_iiiii (blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8:672813)
    at invoke_iiiii (blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8:526645)
    at <anonymous>:wasm-function[79587]:0x17b1821
    at <anonymous>:wasm-function[78880]:0x17902d3
    at <anonymous>:wasm-function[4416]:0x1e2f00
    at <anonymous>:wasm-function[4414]:0x1e2bd8
    at <anonymous>:wasm-function[24138]:0xbe6bc5
    at <anonymous>:wasm-function[10875]:0x453836
    at <anonymous>:wasm-function[10605]:0x430d05
    at <anonymous>:wasm-function[10605]:0x430d1a
    at <anonymous>:wasm-function[10600]:0x430823
    at <anonymous>:wasm-function[10593]:0x42e77f
    at dynCall_v (<anonymous>:wasm-function[82486]:0x18781dd)
    at Object.dynCall_v (blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8:683137)
    at browserIterationFunc (blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8:357211)
    at Object.runIter (blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8:360272)
    at Browser_mainLoop_runner (blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8:358734)
    printErr @ UnityLoader.js:4
    15:57:21.333 UnityLoader.js:3 Invoking error handler due to
    Uncaught RuntimeError: memory access out of bounds
    15:57:21.333 VM15:88 TSS: caught alert
    15:57:21.333 VM15:62 TSS: Checking if repeated 2 times for interval 5000 against data: Object
    15:57:21.333 blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8 Uncaught RuntimeError: memory access out of bounds
    at <anonymous>:wasm-function[9027]:0x38f5fb
    at <anonymous>:wasm-function[14465]:0x5edf95
    at <anonymous>:wasm-function[62212]:0x13975ae
    at <anonymous>:wasm-function[62211]:0x139755e
    at <anonymous>:wasm-function[40240]:0xf11f3f
    at <anonymous>:wasm-function[32974]:0xd6ff04
    at <anonymous>:wasm-function[40238]:0xf0a934
    at <anonymous>:wasm-function[40273]:0xf193aa
    at <anonymous>:wasm-function[32397]:0xd4df1e
    at <anonymous>:wasm-function[40118]:0xf02ba0
    at <anonymous>:wasm-function[37538]:0xe7f4f8
    at <anonymous>:wasm-function[78360]:0x177abea
    at <anonymous>:wasm-function[29954]:0xd13b7a
    at dynCall_iiiii (<anonymous>:wasm-function[82469]:0x1877f00)
    at Object.dynCall_iiiii (blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8:672813)
    at invoke_iiiii (blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8:526645)
    at <anonymous>:wasm-function[79587]:0x17b1821
    at <anonymous>:wasm-function[78880]:0x17902d3
    at <anonymous>:wasm-function[4416]:0x1e2f00
    at <anonymous>:wasm-function[4414]:0x1e2bd8
    at <anonymous>:wasm-function[24138]:0xbe6bc5
    at <anonymous>:wasm-function[10875]:0x453836
    at <anonymous>:wasm-function[10605]:0x430d05
    at <anonymous>:wasm-function[10605]:0x430d1a
    at <anonymous>:wasm-function[10600]:0x430823
    at <anonymous>:wasm-function[10593]:0x42e77f
    at dynCall_v (<anonymous>:wasm-function[82486]:0x18781dd)
    at Object.dynCall_v (blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8:683137)
    at browserIterationFunc (blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8:357211)
    at Object.runIter (blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8:360272)
    at Browser_mainLoop_runner (blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8:358734)
    16:01:56.364 180d3779-496e-402c-a098-e8862bd29549:8 (325.46/336.6418/3d854/UIHandler.893) OnApplicationFocus True

    16:01:56.379 blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8 An abnormal situation has occurred: the PlayerLoop internal function has been called recursively. Please contact Customer Support with a sample project so that we can reproduce the problem and troubleshoot it.
    (Filename: Line: 397)


    _JS_Log_Dump @ blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8
    16:01:57.670 blob:http://scott17/180d3779-496e-402c-a098-e8862bd29549:8 An abnormal situation has occurred: the PlayerLoop internal function has been called recursively. Please contact Customer Support with a sample project so that we can reproduce the problem and troubleshoot it.
    (Filename: Line: 397)
     
  28. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,265
    The following is the suggest temporary change.

    In the TMPro_UGUI_Private.cs in the OnPreRenderCanvas() function around line 1616, make the following change which will force the text input to always be parsed when any of the text properties are changed.

    Code (csharp):
    1.  
    2. // Reparse the text if the input has changed or text was truncated.
    3. if (true) // m_isInputParsingRequired || m_isTextTruncated)
    4. {
    5.     #if TMP_PROFILE_ON
    6.     Profiler.BeginSample("TMP - ParseInputText()");
    7.     #endif
    8.  
    Make sure the change is done in the Global Package cache otherwise the change will be reverted when Unity is restarted.

    Let me know if this change resolves your issue.
     
    ScottAdams likes this.
  29. ScottAdams

    ScottAdams

    Joined:
    Nov 23, 2016
    Posts:
    55
    I found the file and made the change as suggested. For others, my file was at:
    C:\Users\msadams\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.textmeshpro@2.1.3\Scripts\Runtime\TMPro_UGUI_Private.cs

    So far it appears to have fixed the problem. We are continuing to test.
     
  30. isaac-ashdown

    isaac-ashdown

    Joined:
    Jan 30, 2019
    Posts:
    69
    Sorry for the late reply - We do have some full-screen UI Image components that we use to do a full-screen fade-to-black transition. No full screen texts that I know of though.

    In terms of something special, after looking at the clip again, I think I can perhaps pinpoint the trigger. If you watch, you can see that our game has a litlle UI element around the cursor Hex, with a number under it and an icon of a purple spiral. This purple spiral is an Image component, not a TMP sprite. Then as the user moves the cursor around, at the exact moment when the flash happens, that text UI is changed to a red number with a percentage sign, and then a red Skull. That skull IS a TMP inline sprite, and there's an animator applied to that text that animates the scale to make it pulse.

    I'm still not sure what that means though... However I see in the other thread that a new TMP version will be coming soon, so I'll be sure to check it out and let you know if the issue seems to have been resolved.
     
  31. isaac-ashdown

    isaac-ashdown

    Joined:
    Jan 30, 2019
    Posts:
    69
    So I've updated the TMP plugin to 2.1.4 and am no longer seeing the exception in the Unity crashreports. Hooray!

    No sign yet of the flashing sprite sheet but I'll keep an eye on it for a while more.
     
unityunity