mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-09 01:52:32 +02:00
Dedup contours during merging of resinTrapGroups.
Fix for edge case where a contour is in multiple groups and they get merged. Doesn't fix root cause of the contour being placed in 2 groups, but for the time being this works around it be deduping during the merge
This commit is contained in:
@@ -871,10 +871,23 @@ namespace UVtools.Core.Managers
|
||||
else
|
||||
{
|
||||
var combinedGroup = new List<(VectorOfVectorOfPoint contour, uint layerIndex)>();
|
||||
|
||||
/* for reasons not fully understood, in rare cases you can end up with the same contour in multiple groups that are
|
||||
* about to merge. This can cause a use-after-free type error later on when we dispose of a contour.
|
||||
* We can (at least in the short term) remedy this by de-duping the result of the merge */
|
||||
var uniqueCombinedGroup = new HashSet<(VectorOfVectorOfPoint contour, uint layerIndex)>();
|
||||
foreach (var index in overlappingGroupIndexes)
|
||||
{
|
||||
combinedGroup.AddRange(resinTrapGroups[index]);
|
||||
foreach (var p in resinTrapGroups[index])
|
||||
{
|
||||
uniqueCombinedGroup.Add(p);
|
||||
}
|
||||
}
|
||||
combinedGroup.AddRange(uniqueCombinedGroup.ToList());
|
||||
combinedGroup.Add((resinTraps[layerIndex][x], (uint)layerIndex));
|
||||
|
||||
uniqueCombinedGroup.Clear();
|
||||
uniqueCombinedGroup = null;
|
||||
|
||||
for (var index = overlappingGroupIndexes.Count - 1; index >= 0; index--)
|
||||
{
|
||||
@@ -882,7 +895,6 @@ namespace UVtools.Core.Managers
|
||||
resinTrapGroups.RemoveAt(index);
|
||||
}
|
||||
|
||||
combinedGroup.Add((resinTraps[layerIndex][x], (uint)layerIndex));
|
||||
resinTrapGroups.Add(combinedGroup);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user