From 69b2faa96e89847027e293e89f7a4c692f4ac045 Mon Sep 17 00:00:00 2001 From: spherallic Date: Fri, 25 Nov 2022 18:39:58 +0100 Subject: [PATCH] Add safeguards to prevent crashes from invalid flat alignment lines --- Source/Core/Windows/LinedefEditForm.cs | 4 +++- .../Plugins/BuilderModes/General/BuilderPlug.cs | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Source/Core/Windows/LinedefEditForm.cs b/Source/Core/Windows/LinedefEditForm.cs index 2a09b16..4067993 100644 --- a/Source/Core/Windows/LinedefEditForm.cs +++ b/Source/Core/Windows/LinedefEditForm.cs @@ -23,6 +23,8 @@ using System.Windows.Forms; using CodeImp.DoomBuilder.Config; using CodeImp.DoomBuilder.Map; using CodeImp.DoomBuilder.Types; +using SlimDX.Direct3D9; + #endregion @@ -504,7 +506,7 @@ namespace CodeImp.DoomBuilder.Windows s.UpdateCeilingSurface(); } } - if (l.Front.Sector != null) + if (l.Front != null && l.Front.Sector != null) { l.Front.Sector.UpdateFloorSurface(); l.Front.Sector.UpdateCeilingSurface(); diff --git a/Source/Plugins/BuilderModes/General/BuilderPlug.cs b/Source/Plugins/BuilderModes/General/BuilderPlug.cs index fc20ae3..ccb7667 100644 --- a/Source/Plugins/BuilderModes/General/BuilderPlug.cs +++ b/Source/Plugins/BuilderModes/General/BuilderPlug.cs @@ -330,7 +330,20 @@ namespace CodeImp.DoomBuilder.BuilderModes private void HandleSurfaceFlatAlignment(Linedef l, Sector s, FlatVertex[] vertices, ImageData img) { bool useoffsets = l.IsFlagSet("8192"); - float xoffset = useoffsets ? l.Front.OffsetX : -l.Start.Position.x; + + if (useoffsets && l.Front == null) + { + General.Interface.DisplayStatus(StatusType.Warning, "Flat alignment line is set to use offsets, but doesn't have a front side!"); + return; + } + + if (s == null) + { + General.Interface.DisplayStatus(StatusType.Warning, "Flat alignment line points to a non-existent sector!"); + return; + } + + float xoffset = useoffsets ? l.Front.OffsetX : -l.Start.Position.x; float yoffset = useoffsets ? -l.Front.OffsetY : -l.Start.Position.y; float rotation = General.ClampAngle(90f - l.Angle * Angle2D.PIDEG);