IndexOutOfRangeException in FillSpriteVertexBuffers

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 :0
at TMPro.TextMeshProUGUI.GenerateTextMesh () [0x05756] in :0
at TMPro.TextMeshProUGUI.OnPreRenderCanvas () [0x0012c] in :0
at TMPro.TextMeshProUGUI.ForceMeshUpdate (System.Boolean ignoreActiveState, System.Boolean forceTextReparsing) [0x0003a] in :0
at TeletypeTMPro+d__26.MoveNext () [0x000f4] in :0
at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00026] in :0

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

int materialIndex = m_textInfo.characterInfo[i].materialReferenceIndex;
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.

I will try taking a look tomorrow / over the weekend.

Do you have a Case # for the project you uploaded?

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).

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.

We are having similar issue on WebGL builds

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.

Reverting back TextMeshPro to 2.1.1 got rid of error, so it seems that something is wrong in 2.1.3.

Are you able to reliably reproduce this error?

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

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.

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 !

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.

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.

Were you not able to open the project I submitted two months ago? I gave you a case # and all that.

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.

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.

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.

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 move can cut any white edge”

“Cut an edge to mix and ”

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.

Please see if making the change outlined in the following [post ]( TMP: Breaking Chinese Bugs for Traditional ZhuYin ("BoPoMoFo" - Taiwan Locale) page-2#post-6607135)resolves the issue.

I can confirm that this change, when made to version 1.5.3, does stop the exceptions with Unity 2018.4.30f1.

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.