Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: woshihuo12 on August 12, 2014, 08:04:06 AM

Title: UIinput i meet an error..
Post by: woshihuo12 on August 12, 2014, 08:04:06 AM
ArgumentOutOfRangeException: startIndex + length > this.length
Parameter name: length
System.String.Substring (Int32 startIndex, Int32 length) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System/String.cs:356)
UIInput.GetLeftText () (at Assets/NGUI/Scripts/UI/UIInput.cs:987)
UIInput.Insert (System.String text) (at Assets/NGUI/Scripts/UI/UIInput.cs:940)
UIInput.Update () (at Assets/NGUI/Scripts/UI/UIInput.cs:640)

ArgumentOutOfRangeException: startIndex + length > this.length
Parameter name: length
System.String.Substring (Int32 startIndex, Int32 length) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System/String.cs:356)
UIInput.GetSelection () (at Assets/NGUI/Scripts/UI/UIInput.cs:1018)
UIInput.ProcessEvent (UnityEngine.Event ev) (at Assets/NGUI/Scripts/UI/UIInput.cs:877)
UIInput.OnGUI () (at Assets/NGUI/Scripts/UI/UIInput.cs:675)


the bug occur like this:
input two chars like "12",
and input two space so like "12  ",
and use mouse select the value,
the error will occur!

and i notice that:
when you use mouse in a empty uiinput drag..
there will be a space " " in the input field...


and i just change the code like this:


   protected string GetLeftText ()
   {
      int min = Mathf.Min(mSelectionStart, mSelectionEnd);
        return (string.IsNullOrEmpty(mValue) || min < 0) ? "" : mValue.Substring(0, Mathf.Min(min, mValue.Length));
   }

   protected string GetSelection ()
   {
      if (string.IsNullOrEmpty(mValue) || mSelectionStart == mSelectionEnd)
      {
         return "";
      }
      else
      {
         int min = Mathf.Min(mSelectionStart, mSelectionEnd);
         int max = Mathf.Max(mSelectionStart, mSelectionEnd);
            return mValue.Substring(min, Mathf.Min(max - min, mValue.Length));
      }
   }
Title: Re: UIinput i meet an error..
Post by: ArenMook on August 13, 2014, 07:00:45 AM
You need to update your NGUI...