Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IndexOutOfRangeException In InterpolateFast
#1
Hello, I have sometime a little IndexOutOfRangeException when i am initalizing things, I have an error at the return of this function:

Code:
public Vector3 InterpolateFast(float localF)
       {
           float frag;
           int idx = getApproximationIndexINTERNAL(localF, out frag);
           int idx2 = Mathf.Min(Approximation.Length - 1, idx + 1);
           return (Vector3.LerpUnclamped(Approximation[idx], Approximation[idx2], frag));
       }

I have done this extra test to make it work:
Code:
if (idx < 0 || idx >= Approximation.Length || idx2 < 0 || idx2 >= Approximation.Length)
           {
               return (Vector3.zero);
           }

My 2 questions ares: In what condition that peace of code can return an idx || idx2 invalid, and secondly, is my patch with return Vector3.zero is safe or not ? 

Thanks Wink
Reply


Messages In This Thread
IndexOutOfRangeException In InterpolateFast - by UsernameHed - 08-26-2019, 04:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  IndexOutOfRangeException in CurvySplineSegment.LocalFToDistance billowe 2 753 09-06-2022, 06:09 AM
Last Post: sambutle
Question IndexOutOfRangeException in CurvySplineSegment.LocalFToDistance function mchangxe 13 3,243 05-06-2021, 12:56 PM
Last Post: _Aka_

Forum Jump: