Add safeguards to prevent crashes from invalid flat alignment lines

This commit is contained in:
spherallic 2022-11-25 18:39:58 +01:00
parent ccd15d6f94
commit 69b2faa96e
2 changed files with 17 additions and 2 deletions

View file

@ -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();

View file

@ -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);