diff --git a/Source/Core/Map/MapSet.cs b/Source/Core/Map/MapSet.cs index dbe9db6..c345c0a 100644 --- a/Source/Core/Map/MapSet.cs +++ b/Source/Core/Map/MapSet.cs @@ -2105,9 +2105,9 @@ namespace CodeImp.DoomBuilder.Map ICollection nearbyfixedverts = FilterByArea(fixedverts, ref editarea); if(!SplitLinesByVertices(movinglines, nearbyfixedverts, STITCH_DISTANCE, movinglines, mergemode)) return false; - - // Split non-moving lines with selected vertices - fixedlines = FilterByArea(fixedlines, ref editarea); + + // Split non-moving lines with selected vertices + fixedlines = new HashSet(fixedlines.Where(fixedline => !fixedline.IsDisposed)); if(!SplitLinesByVertices(fixedlines, movingverts, STITCH_DISTANCE, movinglines, mergemode)) return false; @@ -2347,11 +2347,13 @@ namespace CodeImp.DoomBuilder.Map builder.CreateSector(sector, null); } - // Remove any sides that weren't part of a sector - for (int i = 0; i < edgeCount; i++) - { - LinedefSide ls = edges[i]; - if (ls.Ignore || ls.Line == null) continue; + // Remove any sides that weren't part of a sector + for (int i = 0; i < edgeCount; i++) + { + LinedefSide ls = edges[i]; + if (ls.Ignore || ls.Line == null) continue; + if (ls.Line.Start == null || ls.Line.End == null) + throw new Exception("ls line is null"); if(ls.Front) { @@ -3066,8 +3068,8 @@ namespace CodeImp.DoomBuilder.Map // Trash vertex v.Dispose(); - } - } + } + } } break; @@ -3076,12 +3078,20 @@ namespace CodeImp.DoomBuilder.Map } } } - - return true; + + // [ZZ] note: disposing a vertex means also disposing all attached linedefs! + // we need to iterate through our lines collection and make sure no disposed linedefs exist there. + // also, just in case, do it for vertices as well, because vertices can be chain-disposed. + foreach (Linedef line in lines.Where(line => line.IsDisposed).ToList()) + while (lines.Remove(line)); + foreach (Vertex vert in verts.Where(vert => vert.IsDisposed).ToList()) + while (verts.Remove(vert)); + + return true; } /// Splits lines by lines. Adds new lines to the second collection. Returns false when the operation failed. - public static bool SplitLinesByLines(HashSet lines, HashSet changedlines, MergeGeometryMode mergemode) //mxd + public static bool SplitLinesByLines(ICollection lines, HashSet changedlines, MergeGeometryMode mergemode) //mxd { if(lines.Count == 0 || changedlines.Count == 0 || mergemode == MergeGeometryMode.CLASSIC) return true;