C# crashes on recompute and on load

I’ve encountered a weird issue
I created a C# component that was working fine when testing
but after saving the file, when opening the file again, the component causes crashes when enabled

When debuging, I commented out section by section and it all works
after uncommenting all the sections, the component works again
I can change all the inputs and it’s fine, but if I press Recompute or save, it’ll all crash again.

I don’t know why it’s cause crashes, can someone please check and let me know?

I’m on Version 6 SR31
(6.31.20315.17001, 11/10/2020)

attached is the component that crashes
crashingComponent.gh (17.3 KB)

Hi @evo85210,

Maybe I am confused, but it appears run is never set to false. Thus your while loop runs indefinitely. You might want to verify this block of code is correct, logically.

– Dale

Hi @dale

I have the exit condition here (line 118):

else if((possible && intersects.Count > 0) || !possible)
        run = false; //if no intersection exit loop
      }

I use the boolean possible to check if intersection in one direction is possible
bool possible = Possible(crv, pln, dist);
First I test for below the plane, then above the plane

by commenting out the while loop and printing out the possible boolean
with the internalised values I get :

False (for below)
True (for above)

For intersections below the plane
possible = false, so in the while loop, if there’s no intersections the !possible portion of the exit condition would be true, which then sets run to be false

For intersections above the plane
possible = true, so since either/both start/end point of the curve is above the plane, there should be at least one intersection, the plane will continously move up in each iteration:
pln.Origin = pln.Origin + (pln.Normal * dist);
at which point when an intersection happens, intersects.Count > 0
so after the intersection, if there’s a step when there’s no intersection
possible = true and intersects.Count > 0 makes (possible && intersects.Count > 0) = true which allows for the exit run = false

I don’t think my logic is wrong? or maybe I’m misunderstanding something?

thanks,

Victor

Hi @evo85210,

When I ran your solution, a false condition was never met (e.g. an infinite loop). Or maybe I’m confused on how to run your solution.

– Dale

Hi @dale

I think I see the issue you’re saying, but I don’t think this is issue with my code? Please check file attached.
I’ve commented out the while loop and added a print after the possible boolean

bool possible = Possible(crv, pln, dist);
Print(possible.ToString()); 

on load and recompute, it prints out
True
False
which is incorrect, but if I slide the slider the output becomes
False
True
which is correct, and even after changing slider value to the original 3.4, I still get the correct output
Only upon opening and recompute are the values wrong
Video:https://youtu.be/9yZdxA1kJVQ

crashingComponent-Isolated.gh (9.5 KB)

EDIT:
I’ve narrowed it down to cSys.ZAxis on line165
on load and recompute, the ZAxis does not output any value (0,0,0 instead of 0,0,1)
it seems like on load and recompute this.Component.Params.Input[2].VolatileDataCount will detect a input even tho there’s nothing inputted, this prevents me from assigning the correct default value of new Vector3d(0, 0, 1)

So I guess the main question now is:
How do I define default values to an input if there’s no input (the way I’ve been doing it has weird quirks)

I would strongly suggest something like this (always use a safe exit plan like N of attempts or some other):

CrvPlane_Ccx_EntryLevel_V1.gh (5.7 KB)

Yes a for sure backup if a good idea.

Do you know how to define default values to an input if there’s no input?

Have a look on the attached (what happens if pt is Point3d.Unset? (i.e. no input), what happens if the dir List is wrong? etc etc).

CrvPlane_Ccx_EntryLevel_V1A.gh (119.7 KB)

BTW: Sampling the Ccx events class in a List is pointless … since you’ll need some other Method to “extract” data (points, params etc etc). So do the right thing and get all these in a DataTree (of type object). For so few items the cost of unboxing is nothing.