Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

I​ndexOutOfRangeException trying to confirm fix.

A topic by holdingjason@gmail.com created Nov 23, 2020 Views: 157 Replies: 5
Viewing posts 1 to 2
(1 edit)
v1.9.1

Want to confirm this has been fixed.  Repro on this is very hard and cannot repro it consistently so figured I would check if it was already known and fixed (appears after 1.9.1 there was some fixes related to this in v.1.10 but not sure.  This would be a very bad bug to slip through the cracks, especially since it appears to be a timing issue and having text longer then the text container.

  • Fixed array lengths not matching up under specific circumstances.

The error occurred in RebuildTextInfo() at this line.  i was larger the info array.

       Font myFont = info[i].fontData != null ? info[i].fontData.font : font; //use info's font, or default?

Thanks.

IndexOutOfRangeException: Index was outside the bounds of the array. SuperTextMesh.RebuildTextInfo () (at Assets/Clavian/SuperTextMesh/Scripts/SuperTextMesh.cs:2622) SuperTextMesh.Rebuild (System.Single startTime, System.Boolean readAutomatically, System.Boolean executeEvents) (at Assets/Clavian/SuperTextMesh/Scripts/SuperTextMesh.cs:1349) SuperTextMesh.Rebuild (System.Single startTime, System.Boolean readAutomatically) (at Assets/Clavian/SuperTextMesh/Scripts/SuperTextMesh.cs:1327) SuperTextMesh.Rebuild () (at Assets/Clavian/SuperTextMesh/Scripts/SuperTextMesh.cs:1317) SuperTextMesh.set_text (System.String value) (at Assets/Clavian/SuperTextMesh/Scripts/SuperTextMesh.cs:681) 

Developer

Hey!

Repro of this is quite hard to do, myself... iirc, that fix in the changelog was something I found myself and wasn't reported by a member of the community, so... it could potentially be the same fix. I believe I added another array length check somewhere to make sure the length of the info array never exceeds the hyphenedText string.

Either way, if this happened in v1.9.1, I won't be able to fix it unless it's still happening in the latest version, so... please upgrade if you can! Please let me know if it still happens, a detailed bug report like this will help me fix the problem quickly.

Thanks.  Yep upgrading to latest and seeing if it shows up again.  

The repro is tough like you said.  Appears to be related to text that would extend beyond the setup limits of the control AND clicking through ie triggering a full ShowTextAll while its reading in the text.  It appears to be timing based ie it happens, my guess when the text is being rendered out beyond the limits and you try and do a ShowTextAll and immediately set the text to the next statement.  Like you said something in the order of that must be resetting the array vars.  My guess its doing something like setting the next text and array length to the next statement which is shorter then the previous text but rebuild of the previous text is still taking place or gets triggered again.   If I can come up with a hard repro I will pass it along but like I said so far little luck but used to be able to get it 1 out of maybe 5 times etc.

Developer

Can you send me the debug log again? I don't know where the error is happening anymore.

in V.1.9.1 you can see where I attempted to catch the errors myself but just kept moving the problem.  

 Debug.LogError("SUPERTEXTMESH Index Length Error");

The first error was here.  info was not large enough for i.

                    Font myFont = info[i].fontData != null ? info[i].fontData.font : font; //use info's font, or default?
                                                                                           //info[i].size *= bestFitMulti;


void RebuildTextInfo()
    {
        drawText = ParseText(text); //remove parsing junk (<col>, <b>), and fill textinfo again
        lineBreaks.Clear(); //index of line break characters, for centering
        hyphenedText = string.Copy(drawText);
        CalculateLineHeights(); //figure out line heigts for unwrapped equation
                                //Debug.Log("lines: " + lineHeights.Count);
        Vector3 pos = new Vector3(info.Count > 0 ? info[0].indent : 0f,
                                lineHeights.Count > 0 ? -lineHeights[0] : -size,
                                0f); //keep track of where to place this text

        if (bestFit != BestFitMode.Off)
        {
            FigureOutUnwrappedLimits(pos);
        }
        else
        {
            unwrappedBottomRightTextBounds.x = 1f;
            unwrappedBottomRightTextBounds.y = 1f;
        }
        CalculateBestFitMulti();
        //apply this multi to every letter early
        for (int i = 0; i < hyphenedText.Length; i++)
        {
            info[i].size *= bestFitMulti;
        }

        CalculateLineHeights(); //now with multi applied, redo line heights

        pos.x = info.Count > 0 ? info[0].indent : 0f;
        pos.y = lineHeights.Count > 0 ? -lineHeights[0] : size;
        totalWidth = 0f;
        allFonts.Clear();
        if (AutoWrap > 0f)
        { //use autowrap?

            //TODO see if setting "quality" to be info[i].ch.size has any GC issues, now: 2016-10-26
            for (int i = 0, iL = hyphenedText.Length; i < iL; i++)
            { //first, get character info...
                if (i < info.Count && i < hyphenedText.Count())
                {
                    Font myFont = info[i].fontData != null ? info[i].fontData.font : font; //use info's font, or default?
                                                                                           //info[i].size *= bestFitMulti;

                    myFont.RequestCharactersInTexture(hyphenedText[i].ToString(), GetFontSize(myFont, info[i]), info[i].ch.style);
                    
                    CharacterInfo ch;

                    if (i < info.Count && i < hyphenedText.Count())
                    {
                        if (myFont.GetCharacterInfo(hyphenedText[i], out ch, GetFontSize(myFont, info[i]), info[i].ch.style))
                        { //does this character exist?
                            info[i].ch = ch; //remember character info!
                                             // If the character changed, update the cached sizing values.
                            info[i].UpdateCachedValuesIfChanged();
                            // SetTextGenSettings(info[i], i);
                        }
                        //else, don't draw anything! this charcter won't have info
                        //...is how it USED to work! instead, lets draw it in a fallback font:
                        else
                        {
                            myFont = data.defaultFont;
                            if (myFont.GetCharacterInfo(hyphenedText[i], out ch, GetFontSize(myFont, info[i]), info[i].ch.style))
                            {
                                //change the font on this mesh to the default
                                info[i].fontData = new STMFontData(data.defaultFont);
                                info[i].ch = ch; //remember character info!
                                info[i].UpdateCachedValuesIfChanged();
                                // SetTextGenSettings(info[i], i);
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("SUPERTEXTMESH Index Length Error");
                    }

                    if (!allFonts.Contains(myFont))
                    { //if this font is not listed yet
                        allFonts.Add(myFont);
                    }
                }
                else
                {
                    Debug.LogError("SUPERTEXTMESH Index Length Error");
                }
            }


Developer

Actually, I can't see it because in the latest version, when I hit ctrl+f for that line, it's commented out! So if the error is still happening in the latest version, it must be happening somewhere else. Please update to the latest version and if the error pops up, please send me the error Unity throws, and I'll be able to track it down at it's source.