Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Destroying curvyspline instances
#1
What is the correct procedure to remove an instance of a CurvySpline from memory?

For example I've created an object which travels along a spline, have set up the OnPositionReached event to fire something else, but part of that is to then remove the spline from view, along with the relevant modules (Generator, InputSplinePath, DeformMesh, etc).

I'm sure this is of course the wrong way, but if I Destroy the object, I get errors of:

Code:
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
or
Code:
NullReferenceException: Object reference not set to an instance of an object

Have checked the docs, or rather searched for words like "Remove", "Destroy", "Close" etc but nothing seems to be pointing me to the right direction.
Reply
#2
Hi
Deleting the game object of the spline is usually the easiest and best way to remove a spline.
The errors you get seem to be from due to some code still trying to access the spline after it being destroyed. To help you further I need more information.
1- Please provide the whole error messages (with the stack trace).
2- Do you use the spline in your own code, or do you use it only with code provided in Curvy Splines?
Thank you
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#3
Hi _Aka_,

Hope you're good.

So the full error message for the Index out of Range is as follows:
Code:
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <c040dc59dcbc4ddb95ffc99a02c8bae9>:0)
System.Collections.ObjectModel.ReadOnlyCollection`1[T].get_Item (System.Int32 index) (at <c040dc59dcbc4ddb95ffc99a02c8bae9>:0)
FluffyUnderware.Curvy.CurvySpline.DistanceToSegment (System.Single distance, System.Single& localDistance, System.Boolean& isOnSegmentStart, System.Boolean& isOnSegmentEnd, FluffyUnderware.Curvy.CurvyClamping clamping) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Splines/CurvySpline.cs:1768)
FluffyUnderware.Curvy.CurvySpline.DistanceToSegment (System.Single distance, System.Single& localDistance, FluffyUnderware.Curvy.CurvyClamping clamping) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Splines/CurvySpline.cs:1719)
FluffyUnderware.Curvy.CurvySpline.DistanceToTF (System.Single distance, FluffyUnderware.Curvy.CurvyClamping clamping) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Splines/CurvySpline.cs:1672)
FluffyUnderware.Curvy.Controllers.SplineController.AbsoluteToRelative (System.Single worldUnitDistance) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/SplineController.cs:573)
FluffyUnderware.Curvy.Controllers.CurvyController.get_RelativePosition () (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/CurvyController.cs:515)
FluffyUnderware.Curvy.Controllers.CurvyController.ComputeTargetPositionAndRotation (UnityEngine.Vector3& targetPosition, UnityEngine.Vector3& targetUp, UnityEngine.Vector3& targetForward) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/CurvyController.cs:894)
FluffyUnderware.Curvy.Controllers.SplineController.ComputeTargetPositionAndRotation (UnityEngine.Vector3& targetPosition, UnityEngine.Vector3& targetUp, UnityEngine.Vector3& targetForward) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/SplineController.cs:722)
FluffyUnderware.Curvy.Controllers.CurvyController.InitializedApplyDeltaTime (System.Single deltaTime) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/CurvyController.cs:860)
FluffyUnderware.Curvy.Controllers.SplineController.InitializedApplyDeltaTime (System.Single deltaTime) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/SplineController.cs:709)
FluffyUnderware.Curvy.Controllers.CurvyController.ApplyDeltaTime (System.Single deltaTime) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/CurvyController.cs:1410)
FluffyUnderware.Curvy.Controllers.CurvyController.Update () (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/CurvyController.cs:768)



And for the NullReferenceException is here:
Code:
NullReferenceException: Object reference not set to an instance of an object
FluffyUnderware.Curvy.Controllers.SplineController.HandleReachingNewControlPoint (FluffyUnderware.Curvy.CurvySplineSegment controlPoint, System.Single controlPointPosition, FluffyUnderware.Curvy.CurvyPositionMode positionMode, System.Single currentDelta, System.Boolean& cancelMovement, FluffyUnderware.Curvy.CurvySplineSegment& postEventsControlPoint, System.Boolean& postEventsIsControllerOnControlPoint, System.Single& postEventsControlPointPosition) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/SplineController.cs:1540)
FluffyUnderware.Curvy.Controllers.SplineController.EventAwareMove (System.Single distance) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/SplineController.cs:1130)
FluffyUnderware.Curvy.Controllers.SplineController.Advance (System.Single speed, System.Single deltaTime) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/SplineController.cs:653)
FluffyUnderware.Curvy.Controllers.CurvyController.InitializedApplyDeltaTime (System.Single deltaTime) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/CurvyController.cs:844)
FluffyUnderware.Curvy.Controllers.SplineController.InitializedApplyDeltaTime (System.Single deltaTime) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/SplineController.cs:709)
FluffyUnderware.Curvy.Controllers.CurvyController.ApplyDeltaTime (System.Single deltaTime) (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/CurvyController.cs:1410)
FluffyUnderware.Curvy.Controllers.CurvyController.Update () (at Assets/Plugins/ToolBuddy/Assets/Curvy/Scripts/Controllers/CurvyController.cs:768)

I'm using the spline in my own code, when the OnPositionResearchSetting is executed, I'm basically invoking a delegate on the object that animates the spline whereby it destroys the gameobject containing the CurvySpline components.

However, based on what you said about how it should work, I'm wondering if perhaps the problem could be with my code so I'm going to go back and rethink things.

Apologies, this could be totally my fault with not waiting for the animation CurvySplines to complete what it needs to do before deleting it.

Will let you know.
Reply
#4
It might indeed be caused by that.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#5
Sorted!!

If anyone else has a similar problem, you can destroy the objects but in my case because I was destroying all children in a parent, I should have cleared the Spline from the SplineController first.

Doing that resolved the issue and now, zero errors when animations have completed their job and are removed from screen.
Reply
#6
Thank you for the update.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  CurvySpline Optimize Candy 1 6 08-02-2024, 08:35 AM
Last Post: _Aka_
  I have a question about curvySpline haifeng.huang 12 33 07-14-2023, 09:34 AM
Last Post: _Aka_
  "Deadloop in CurvySPline.Refresh" spam Valkymaera 3 12 05-30-2023, 10:56 AM
Last Post: _Aka_
  Is curvyspline a good solution for a 2D rail grinding game? bazz_boyy1 2 8 03-01-2022, 11:49 AM
Last Post: _Aka_

Forum Jump: