Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Got Position { Nan } error.
#1
Bug 
I was implement the dynamic generate path feature in my game.
however something was wrong.
seem like the coordinate calculation in "ComputeTargetPositionAndRotation" had an issue.

so the yellow line (bezier curve) in video was generate via "CurvySpline.Create()";
and calling "CurvySpline.Destroy()" to destroy itself.

when I try to use the generated path in runtime,
however nothing related to CurvySpline.Destroy().
Destroy right after travel didn't work, I need to delay 1 sec (yeah~ so dirty)
and then I tried even didn't Destroy that CurvySpline, at some point these error still popup ????


here is the video log.


here is the error message.
btw, rotation also wrong it's Vector3.zero.

transform.position assign attempt for 'SpaceShip_Small(Clone) #0003' is not valid. Input position is { NaN, NaN, NaN }.
UnityEngine.TransformConfusedet_position(Vector3)
FluffyUnderware.Curvy.Controllers.CurvyController:InitializedApplyDeltaTime(Single) (at Assets/Plugins/Curvy/Controllers/CurvyController.cs:710)
FluffyUnderware.Curvy.Controllers.SplineController:InitializedApplyDeltaTime(Single) (at Assets/Plugins/Curvy/Controllers/SplineController.cs:531)
FluffyUnderware.Curvy.Controllers.CurvyController:ApplyDeltaTime(Single) (at Assets/Plugins/Curvy/Controllers/CurvyController.cs:1014)
FluffyUnderware.Curvy.Controllers.CurvyController:Update() (at Assets/Plugins/Curvy/Controllers/CurvyController.cs:605)


not sure if it help, and here is the class I used to generate and destroy CurvySpline.
Code:
protected class TempPath : System.IDisposable
{
public CurvySplineSegment start => dynamicPath.FirstVisibleControlPoint;
public CurvySplineSegment end => dynamicPath.LastVisibleControlPoint;
public float pathLength => dynamicPath.Length;
public float targetTf;

public CurvySpline dynamicPath;
public CurvySpline targetPath;
private bool disposedValue;

public TempPath(CurvySpline _dynamicPath, CurvySpline _target, float _targetFt)
{
dynamicPath = _dynamicPath;
targetPath = _target;
targetTf = _targetFt;
}
~TempPath()
{
Dispose(disposing: false);
}

/// <summary>Generate temp path</summary>
/// <param name="agent">the agent transfrom for calculate start tangent.</param>
/// <param name="to">target curve wanted to move on.</param>
/// <param name="toFt">-1f : auto search closest</param>
/// <returns></returns>
public static TempPath GeneratePathTo(CurvyController agent,
CurvySpline to, float toFt = -1f)
{
if (to == null)
throw new System.NullReferenceException();

// Generate path !
CurvySpline curve = CurvySpline.Create();
curve.Interpolation = CurvyInterpolation.Bezier;
curve.Orientation = CurvyOrientation.Static;
curve.AutoEndTangents = true;
curve.Closed = false;
curve.GizmoColor = Color.yellow;
curve.ShowGizmos = true;
curve.CacheDensity = 30;

// point on travel path.
Vector3 startPoint = agent.transform.position;
Vector3 startTangent = agent.transform.forward;

CurvySplineSegment start = curve.Add(startPoint, Space.World);
start.AutoHandles = false;
start.HandleOutPosition = startTangent;
start.HandleIn = -start.HandleOut;

// point to switch path.
float endTF = toFt >= 0f ?
toFt : // will clamp in plugin
to.GetNearestPointTF(startTangent, Space.World);

to.InterpolateAndGetTangentFast(endTF, out Vector3 endPoint, out Vector3 endTangent, Space.World);
CurvySplineSegment end = curve.Add(endPoint, Space.World);
end.AutoHandles = false;
end.HandleInPosition = endTangent;
end.HandleOut = -end.HandleIn;
return new TempPath(curve, to, endTF);
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
dynamicPath?.Destroy();
}

dynamicPath = null;
disposedValue = true;
}
}

public void Dispose()
{
Dispose(disposing: true);
System.GC.SuppressFinalize(this);
}
}
Reply
#2
Hi,
Your video is private.
The error happens when the controller updates itself. So my questions are:
1- on what spline that controller is running? Is it the same spline that gets destroyed (dynamicPath)
2- do you confirm that this error happens after you dispose TempPath?
If so, consider destroying the controller at the same time as the spline it runs on. Or if not possible, stop the controller, or set its spline to null or any other spline still alive
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
(08-14-2020, 02:17 PM)_Aka_ Wrote: Hi,
Your video is private.
The error happens when the controller updates itself. So my questions are:
1- on what spline that controller is running? Is it the same spline that gets destroyed (dynamicPath)
2- do you confirm that this error happens after you dispose TempPath?
If so, consider destroying the controller at the same time as the spline it runs on. Or if not possible, stop the controller, or set its spline to null or any other spline still alive

after two day dig down, finally found the reason.
well an issue was I did something like this.

Code:
SwitchTo(m_TempPath.dynamicPath, 0f, 0f);
since I found switch to are only lerp to target position & rotation, I design to dynamic generate via CurvySpline.Create,
and I did some lazy change to achieve that, I mean "input the ZERO duration."
because of that, following line had divide zero issue.

in SplineController.cs > ComputeTargetPositionAndRotation()
Code:
targetPosition = OptimizedOperators.LerpUnclamped(switchlessPosition, positionOnSwitchToSpline, SwitchProgress);
the problem hidden in getter "SwitchProgress" > "SwitchDuration" that one will be zero.

well, the solution for me was avoid using SwitchTo(), but do as follow when switch_duration == 0.
Code:
base.Stop();
Spline = m_TempPath.dynamicPath;
RelativePosition = float.Epsilon;
Play();

well seem not a complete solution, but it will do.

a little suggestion for author,
perhaps adding a early return cases in "SplineController.cs > ComputeTargetPositionAndRotation()",
e.g.
Code:
if (SwitchDuration <= 0f)
targetPosition = positionOnSwitchToSpline;
else
targetPosition = OptimizedOperators.LerpUnclamped(switchlessPosition, positionOnSwitchToSpline, SwitchProgress);

and I believe you will found the better solution like prevent the Zero duration SwitchTo request on high level.
anyway your call~ thanks for the assist.
Reply
#4
Thanks a lot for the suggestion. Will include it in an upcoming update.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error: Calling TeleportBy on a controller that is stopped jamesunity 5 484 07-13-2020, 12:28 PM
Last Post: _Aka_
  Converting spline collider hit point to spline position jh092 7 696 06-26-2020, 09:48 PM
Last Post: _Aka_
  Extrusion does not match Controller position JasperBPT 3 571 05-26-2020, 10:18 PM
Last Post: _Aka_
  Using timeline to manually animate curvy position. gtpdz 9 5,293 04-18-2020, 06:43 PM
Last Post: _Aka_

Forum Jump: