Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IndexOutOfRangeException in CurvySplineSegment.LocalFToDistance function
#13
Have this happening to me as well. It seem to stem from a "issue" in TFToSegment, where a calculation sometimes come VERY close to 1, causing parts of the later logic to fail with the index out of range exception

Code:
func TFToSegment() ...

            float f = tf * segmentsCount;  // This is the issue, sometimes f comes out as something super close to 1, like 0.9999994 (due to float precision)
            int idx = (int)f; // causing idx to become 0
            localF = f - idx; // localF is still 0.9999994

In my case it happens when calling TFToDistance, which causes the subcalls TFToSegment (setting localF near 1), the returned segment (probably the wrong one due to the rounding error) is used to call LocalFToDistance, again sanity checks are passed to localF being close to 1 but not 1. This ends up calling getApproximationIndexINTERNAL, which again passes sanity checks, and returns a index equal to the size of ApproximationDistances.Length, causing the exception to happen.

Wonder if most "<some float> == 1" checks would be better off replaced with Mathf.Approximately(<some float>, 1)

Edit: In our case, segmentsCount was 32, and the tf value used as input was 0.0312499981 instead of 0.3125 due to float rounding errors (which are quite common).
Reply


Messages In This Thread
RE: IndexOutOfRangeException in CurvySplineSegment.LocalFToDistance function - by Sacryn - 05-05-2021, 01:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Disabling a CurvySplineSegment results in NullRefException Lupos 1 6 10-02-2023, 09:55 AM
Last Post: _Aka_
  Custom CurvySplineSegment prefabs Lupos 1 10 10-02-2023, 09:36 AM
Last Post: _Aka_
  Does Curvy has gameobjects pooling system function? Chanon 7 13 09-07-2023, 12:43 PM
Last Post: _Aka_
  IndexOutOfRangeException in CurvySplineSegment.LocalFToDistance billowe 2 753 09-06-2022, 06:09 AM
Last Post: sambutle

Forum Jump: