Edit after solved: This was a lot of words to describe a problem that stemmed from-
- Passing classes around as generic parameters instead of implementing GH_Goo/GH_Param.
- Not completely understanding how class references work.
I was basically appending data to an upstream class because I thought a reference was actually a whole new copy. (It used
new, but just passed a reference into the constructor.)
I’ve run into an issue with data “persisting” when the input for an upstream component is changed. It only happens when the data is stored in a class and passed as a generic parameter (instead of passed directly as a curve, point, etc.). If I force a recompute the program runs correctly with the “real” input, but until then every change is “stored” somehow.
I managed to put together a minimal (smaller than the actual, but still a handful of code) reproduction here, if you want to take a closer look:
And here’s a quick step through. Data in a class is enclosed in these <>.
Packager takes the rhino geometry and makes a new instance of GeometryFormat
The class contains a list of curves and a list of points.
<G>and counts how many points are contained in a curve.
Adjuster takes curves and makes a new instance of AdjustmentFormat
Merger takes the old
<A>and outputs a new GeometryFormat that contains both curves.
<G>is run into another copy of the Operator component and outputs the right amount.
If I move the curve being fed into Adjuster, the final count is updated but includes the 12 points previously counted. I don’t think this is an issue with the counter variable because it’s set to 0 at the start of Operator’s SolveInstance. And because…
If I move the rectangle back down, it will not re-count the points included in step 2.
And last, if I tell grasshopper to recompute, I get the expected result.
In short, if I make changes to the Adjuster component, grasshopper will solve as if it had a copy of every input since the last recompute. I’d like it to only work with the current input.
Am stumped on what’s going on because I’ve been passing classes around in this project for a while now. One new thing here is the repeat use of the operator component, though. If this has something to do with how grasshopper is handling data, is there a way to tell it to “fully recompute” each time?
Thanks for any tips.