Updated to Unity 5.1.1f1 "String too long for TextMeshGenerator. Cutting off characters."

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.

Pretty sure you are running into the same issue I’ve had for along time now. I’ve also submitted a bug report on this as well. FogBugz

Unable to display more then 65536 (IE: UInt16) characters or so in a text area. Pretty sure this bug has existed for some time now and it severely limiting for various scenarios especially when creating unity editor gui’s. See related video walking through here - YouTube

The GUILayout.TextArea method accepts a 32bit int for a max length parameter. Internally the method call stack ends up in the GUIStyle.INTERNAL_CALL_Internal_GetCursorPixelPosition method where it throws an exception.

If we look at the method signature “void INTERNAL_CALL_Internal_GetCursorPixelPosition(IntPtr target, ref Rect position, GUIContent content, int cursorStringIndex, out Vector2 ret);” we see that the cursorStringIndex parameter is defined as a “int” (32 bits).
My decompilation program does not allow me to dive deeper but the bug is obvious by this point. The INTERNAL_CALL_Internal_GetCursorPixelPosition method seems to be checking if the number of characters in the “content” argument is less then or equal to UInt16.MaxValue thus the error being thrown out to the unity console (via the C++ equivalent) as “count <= std::numeric_limits::max()”. (related link http://www.cplusplus.com/reference/limits/numeric_limits/)

In fact the entire call stack starting with the GUILayout.TextArea method all the way down to the INTERNAL_CALL_Internal_GetCursorPixelPosition method take a “int” as an argument.

This is where I believe the problem is located. Why it’s checking against a UIn16 ala the MS-DOS era is beyond my comprehension but there in lies the problem none the less. Myself and I’m sure a lot of other unity developers would very much appreciate this being fix in a timely manner as it is an issue I have ran into in the past on multiple occasions and to date there still has not been a fix for it.

I wonder if anything happened with this issue?
I have made a custom log/console type of window and the limitation to 65536 is pretty severe for me.