Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Infinite loop in FixedDistance mesh generation
#1
Hi there,

I'm working on dynamic cylinder generation at runtime and I came across a possible infinite loop when using a SplinePathMeshBuilder with Extrusion Mode set to Fixed Distance.

I've narrowed it down to the following while loop in the Prepare() method of SplinePathMeshBuilder.

Code:
case MeshExtrusion.FixedDistance:
    float d = Spline.TFToDistance(FromTF);
    tf = Spline.DistanceToTF(d);
    while (tf < ToTF) {
        scale = getScale(tf);
        mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, d, scale));
        d += ExtrusionParameter;
        tf = Spline.DistanceToTF(d);
    }

Through debugging, I've found that the calculated value of tf can stay at 0.9999999 indefinitely when ToTF is 1, therefore causing an infinite loop.

A repro project is attached to this post. To repro:
  • Open the project in latest stable Unity release
  • Open the "main" scene.
  • Hit play. If Unity doesn't freeze in 2-3 seconds, exit Play mode and enter it again. It shouldn't take more then 3-4 tries to cause the infinite loop.

I figured this could be solved by using an epsilon in the while loop condition but didn't know if that would have any nasty side-effects, which is why I'm posting here.

Looking forward to a solution to this. Thanks!
Reply
#2
I just wanted to say I think I've been running into this problem, but I wasn't able to nail down the cause.

Thank you for shedding some light on this, I'm going to be doing some testing tonight to see if I can work around the bug until an official solution.

If I find anything to add I'll make sure to note it here
Reply
#3
Hi,

the problem in fact was in DistanceToTF, which doesn't return 1 when it should on all occasions. This got fixed for 1.51.

Thanks for pointing this out!

Jake
Reply
#4
I have a similar issue, Unity Freezes and goes out of memory. I was just playing with Mesh Generation, so I couldn't say what's buggy or not...
Now my scene is fucked up, can't access anymore :p
Reply
#5
(10-09-2013, 01:10 PM)lelag Wrote: I have a similar issue, Unity Freezes and goes out of memory. I was just playing with Mesh Generation, so I couldn't say what's buggy or not...
Now my scene is fucked up, can't access anymore :p

Sorry to hear that Sad The above error was fixed in 1.51, so it would help if you can remember what exactly you did before Unity hangs.
Reply
#6
(10-09-2013, 01:51 PM)Jake Wrote:
(10-09-2013, 01:10 PM)lelag Wrote: I have a similar issue, Unity Freezes and goes out of memory. I was just playing with Mesh Generation, so I couldn't say what's buggy or not...
Now my scene is fucked up, can't access anymore :p

Sorry to hear that Sad The above error was fixed in 1.51, so it would help if you can remember what exactly you did before Unity hangs.

I just tried to generate a mesh from my spline, then changed Extrusion Mode from Adaptive to Fixed Distance.
Made a couple of those generations on multiple splines, then i changed my scene and came back and Unity freezed.

And by commenting this :

Code:
case MeshExtrusion.FixedDistance:
                        /*float d = Spline.TFToDistance(FromTF);
                        tf = Spline.DistanceToTF(d);
                        while (tf < ToTF) {
                            scale = getScale(tf);
                            mSegmentInfo.Add(new CurvyMeshSegmentInfo(this, tf, d, scale));
                            d += ExtrusionParameter;
                            tf = Spline.DistanceToTF(d);
                        }*/
                        break;

Like someone suggested earlier, i could get my scene back.
From that moment I stopped playing with meshes and I'm only using "Adaptive".

Hope I could help.
Reply
#7
Hi,

@Jake, the infinite loop issue is still happening for me with Curvy 1.51.
Could you open the UnityPackage attached to the first post to see if you can't repro the issue there? Thanks.
Reply
#8
Also seeing this issue in my own project with 1.51.
Reply
#9
I'm just looking into this issue.

Edit: Ok, guess it's solved. Locate and replace CurvySpline.DistanceToSegment() with

Code:
public CurvySplineSegment DistanceToSegment(float distance, out float localDistance)
    {
        distance = Mathf.Clamp(distance,0, Length);
        localDistance = 0;
        CurvySplineSegment seg = mSegments[0];
        if (distance == Length) {
            seg = this[Count - 1];
            localDistance = seg.Distance + seg.Length;
            return seg;
        }
            
        
        while (seg && seg.Distance+seg.Length < distance) {
            seg = NextSegment(seg);
        }
        if (seg == null)
            seg = this[Count - 1];
        localDistance = distance - seg.Distance;
        return seg;
    }

Hopefully that will fix it for all times!

Jake

PS: @Voxelboy: I removed your attached scene, because it contains the full Curvy package. Please be more careful next time! This is a public forum...
Reply
#10
THANK YOU for the fix, Jake.

My Unity was freezing with just basic use of the MeshBuilder (caused when I would translate a CP). At some point I couldn't even open my scene, and now I can Big Grin Everything seems to work fine now!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Adjust radius of generated mesh via script? Shackman 1 3 03-26-2024, 01:12 PM
Last Post: _Aka_
  Not seeing mesh extended after following YT PaulM 1 3 02-02-2024, 12:01 PM
Last Post: _Aka_
  Trigger Zones along Spline Mesh dlees9191 1 5 01-05-2024, 10:18 AM
Last Post: _Aka_
  Get spline from generated mesh beartrox 1 5 11-27-2023, 12:30 PM
Last Post: _Aka_

Forum Jump: