I updated to 5.1.1f1 and now whenever I have only a couple hundred characters in a text box I start receiving this exception. Previously I have tested it up to tens of thousands of characters with no issues.
I am using my own custom text component, so I do get a stack trace unlike using unity engines version. The location of the error (line 19, within the if
statement on the method paste):
cachedUnformattedTextGenerator.Populate(m_UnformattedText, settings);
This is a line that exists in Unity’s class normally, I have just renamed some fields and made some high-level changes that do not affect the text generator other than the color. Here is the entire method:
protected override void OnFillVBO(List<UIVertex> vbo)
{
if (font == null)
return;
// We dont care if we the font Texture changes while we are doing our Update.
// The end result of cachedTextGenerator will be valid for this instance.
// Otherwise we can get issues like Case 619238.
m_DisableFontTextureChangedCallback = true;
Vector2 extents = rectTransform.rect.size;
TextGenerationSettings settings = GetGenerationSettings(extents);
cachedTextGenerator.Populate(m_Text, settings);
if (!UnformattedTextBool)
{
settings.color.a = 0;
cachedUnformattedTextGenerator.Populate(m_UnformattedText, settings);
}
cachedUnformattedTextGenerator.Populate(m_UnformattedText, settings);
Rect inputRect = rectTransform.rect;
// get the text alignment anchor point for the text in local space
Vector2 textAnchorPivot = GetTextAnchorPivot(m_FontData.alignment);
Vector2 refPoint = Vector2.zero;
refPoint.x = (textAnchorPivot.x == 1 ? inputRect.xMax : inputRect.xMin);
refPoint.y = (textAnchorPivot.y == 0 ? inputRect.yMin : inputRect.yMax);
// Determine fraction of pixel to offset text mesh.
Vector2 roundingOffset = PixelAdjustPoint(refPoint) - refPoint;
// Apply the offset to the vertices
IList<UIVertex> verts = cachedTextGenerator.verts;
IList<UIVertex> unformattedVerts = cachedUnformattedTextGenerator.verts;
float unitsPerPixel = 1 / pixelsPerUnit;
if (roundingOffset != Vector2.zero)
{
if(NormalTextBool)
{
for (int i = 0; i < verts.Count; i++)
{
UIVertex uiv = verts*;*
uiv.position *= unitsPerPixel;
uiv.position.x += roundingOffset.x;
uiv.position.y += roundingOffset.y;
vbo.Add(uiv);
}
}
if (UnformattedTextBool)
{
for (int i = 0; i < unformattedVerts.Count; i++)
{
UIVertex uiv = unformattedVerts*;*
uiv.position *= unitsPerPixel;
uiv.position.x += roundingOffset.x;
uiv.position.y += roundingOffset.y;
vbo.Add(uiv);
}
}
}
else
{
if(NormalTextBool)
{
for (int i = 0; i < verts.Count; i++)
{
UIVertex uiv = verts*;*
uiv.position *= unitsPerPixel;
vbo.Add(uiv);
}
}
if (UnformattedTextBool)
{
for (int i = 0; i < unformattedVerts.Count; i++)
{
UIVertex uiv = unformattedVerts*;*
uiv.position *= unitsPerPixel;
vbo.Add(uiv);
}
}
}
m_DisableFontTextureChangedCallback = false;
}
Whats going on here, and how can I fix this?
Edit: More information. m_UnformattedText
is the same as m_Text
except with any formatting like <bold> </bold>
…etc stripped out of it.