Skip to content

Commit

Permalink
fix(gh): fixes OutputChange bug in DSO that was forcing a param rebui…
Browse files Browse the repository at this point in the history
…ld everytime (#2895)

* fix(gh): fixes OutputChange bug in DSO that was forcing a param rebuild everytime

* fix(gh): Ensure params are sorted on every change, even single rename
  • Loading branch information
AlanRynne authored Sep 7, 2023
1 parent fdf0f64 commit 7e51efd
Showing 1 changed file with 41 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private bool OutputMismatch()
{
var isDetached = t.StartsWith("@");
var name = isDetached ? t.Substring(1) : t;
var nickChange = Params.Output[i].NickName != t;
var nickChange = Params.Output[i].NickName != name;
var detachChange = (Params.Output[i] as GenericAccessParam).Detachable != isDetached;
return nickChange || detachChange;
}
Expand Down Expand Up @@ -244,46 +244,50 @@ private void AutoCreateOutputs()
renameParam.Name = cleanName;
renameParam.Description = $"Data from property: {cleanName}";
(renameParam as GenericAccessParam).Detachable = isDetached;
return;
}
// Check what params must be deleted, and do so when safe.
var remove = Params.Output
.Select(
(p, i) =>
{
var res = outputList.Find(o => o == p.Name);
return res == null ? i : -1;
}
)
.ToList();
remove.Reverse();
remove.ForEach(b =>
else
{
if (b != -1 && Params.Output[b].Recipients.Count == 0)
Params.UnregisterOutputParameter(Params.Output[b]);
});
// Check what params must be deleted, and do so when safe.
var remove = Params.Output
.Select(
(p, i) =>
{
var res = outputList.Find(o => o == p.Name);
return res == null ? i : -1;
}
)
.ToList();
remove.Reverse();
remove.ForEach(b =>
{
if (b != -1 && Params.Output[b].Recipients.Count == 0)
Params.UnregisterOutputParameter(Params.Output[b]);
});

outputList.Sort();
outputList.ForEach(s =>
{
var isDetached = s.StartsWith("@");
var name = isDetached ? s.Substring(1) : s;
var param = Params.Output.Find(p => p.Name == name);
if (param == null)
outputList.Sort();
outputList.ForEach(s =>
{
var newParam = CreateParameter(GH_ParameterSide.Output, Params.Output.Count) as GenericAccessParam;
newParam.Name = name;
newParam.NickName = name;
newParam.Description = $"Data from property: {name}";
newParam.MutableNickName = false;
newParam.Access = GH_ParamAccess.list;
newParam.Detachable = isDetached;
newParam.Optional = false;
Params.RegisterOutputParam(newParam);
}
if (param is GenericAccessParam srParam)
srParam.Detachable = isDetached;
});
var isDetached = s.StartsWith("@");
var name = isDetached ? s.Substring(1) : s;
var param = Params.Output.Find(p => p.Name == name);
if (param == null)
{
var newParam = CreateParameter(GH_ParameterSide.Output, Params.Output.Count) as GenericAccessParam;
newParam.Name = name;
newParam.NickName = name;
newParam.Description = $"Data from property: {name}";
newParam.MutableNickName = false;
newParam.Access = GH_ParamAccess.list;
newParam.Detachable = isDetached;
newParam.Optional = false;
Params.RegisterOutputParam(newParam);
}
if (param is GenericAccessParam srParam)
srParam.Detachable = isDetached;
});
}

// Regardless of the type of change, we should always sort the params again
var paramNames = Params.Output.Select(p => p.Name).ToList();
paramNames.Sort();
var sortOrder = Params.Output.Select(p => paramNames.IndexOf(p.Name)).ToArray();
Expand Down

0 comments on commit 7e51efd

Please sign in to comment.