Author Topic: UIinput i meet an error..  (Read 2479 times)

woshihuo12

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
UIinput i meet an error..
« 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));
      }
   }
« Last Edit: August 12, 2014, 09:21:15 PM by woshihuo12 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIinput i meet an error..
« Reply #1 on: August 13, 2014, 07:00:45 AM »
You need to update your NGUI...