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
#2
This exception should not happen. With your help I can reproduce the bug and fix it. Do you have a reproduction case that you can send me to reproduce the bug?
Maybe you have the bug because you called the method before the spline is initialized?
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-26-2019, 09:11 PM)_Aka_ Wrote: Maybe you have the bug because you called the method before the spline is initialized?

Yes I think it's exactly the reason Smile
Reply
#4
Ok. Just so you know, there is a CURVY_SANITY_CHECKS preprocessor symbol that you might find interesting
https://curvyeditor.com/documentation/apigeneral#curvy_sanity_checks
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
Nice, ok. I have a similare little issue with that script:
[Image: IHCh2VC4lBG_pool.PNG]

When I am editing a prefabs, who contain a generator (a generator who doesn't have a spline reference by itself),
I get this error in the console when I am editing the prefabs:

InvalidOperationException: Destroying a GameObject inside a Prefab instance is not allowed.

It's not a big deal, I have solve that problem by adding that:

Code:
if (!Application.isPlaying)
           {
               if (!ComponentPool.IsInPrefabStage())
               {
                   DestroyImmediate(item.gameObject);
               }
           }

And the static function:
Code:
private static bool IsInPrefabStage()
       {
#if UNITY_2018_3_OR_NEWER
           var stage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
           return (stage != null);
#else
   return false;
#endif
       }
Reply
#6
Hi,

Thanks for sharing this code.

With the new prefab system, destroying a GameObject inside a Prefab instance is no more allowed through the API. What I think is the correct way to handle this is to make it clear to Curvy's users that the operation they are trying to do (that leads to an attempt of game object destruction) is no more valid. So I added, to the exception message you posted (coming from Unity) an error message explaining exactly what is happening. For example:
"[Curvy] Error while trying to destroy the object 'Create Mesh_5_Mesh000'. This is probably because that object is part of a prefab instance, and Unity 2018.3 and beyond forbid deleting such objects without breaking the prefab link. Please remove the corresponding object from the prefab and try the faulty operation again."

Unfortunately, a lot of users don't read the console. This made think about considering your solution, but I decided that it is not a perfect one neither, because it will make the generator behave differently, and silently, based on whether the generator is part of a prefab or not. I prefer clearly showing that something is wrong, so that users can take the correct steps to fix it.

What do you think about what I said?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#7
I am also thinking about not saving meshes and gameobjects generated by the generator, since they get generated automatically anyway. I have to take a deeper look at this, and consider its retrocompatibility with previous Curvy users.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#8
I also thought about keeping the generated objects from being part of prefabs, to avoid the issue happening when trying to destroy them. I tried to set their hideFlags to HideFlags.DontSave. It works, but those objects become not compatible with global illumination, as explained by this warning from Unity that pops in the console:
"Some MeshRenderers cannot contribute to global illumination, because their HideFlags are set to DontSaveInEditor, HideAndDontSave or DontSaveInBuild."
I haven't yet found the perfect solution
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
  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: