Nodes Viewer Mode: fixed a crash when the NODES lump contains unsupported ZDBSP nodes. Fixes #766

This commit is contained in:
biwa 2022-08-16 14:34:52 +02:00
parent c1e401013b
commit 91010eb92f
2 changed files with 34 additions and 4 deletions

View file

@ -167,8 +167,14 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
General.Editing.CancelMode();
NodesViewerMode newmode = new NodesViewerMode();
General.Editing.ChangeMode(newmode);
newmode.Form.showsegsvertices.Checked = this.showsegsvertices.Checked;
newmode.Form.Location = this.Location; //mxd
// If something went wrong while engaging the mode (for example an unsupported node format was detected)
// the mode will be disposed, so we need to check for it here
if (!newmode.IsDisposed)
{
newmode.Form.showsegsvertices.Checked = this.showsegsvertices.Checked;
newmode.Form.Location = this.Location; //mxd
}
}
#endregion

View file

@ -92,12 +92,36 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
/// </summary>
private bool LoadClassicStructures()
{
List<string> unsupportedheaders = new List<string>() { "ZNOD", "XNOD" };
// Load the nodes structure
MemoryStream nodesstream = General.Map.GetLumpData("NODES");
if(nodesstream.Length < 4)
{
MessageBox.Show("The NODES lump is too short.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
General.Editing.CancelMode();
return false;
}
BinaryReader nodesreader = new BinaryReader(nodesstream);
string header = new string(nodesreader.ReadChars(4));
if(unsupportedheaders.Contains(header))
{
MessageBox.Show("ZDBSP compressed nodes are currently not supported.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
General.Editing.CancelMode();
return false;
}
// Rewind stream position
nodesreader.BaseStream.Position = 0;
int numnodes = (int)nodesstream.Length / 28;
//mxd. Boilerplate!
if(numnodes < 1)
if (numnodes < 1)
{
// Cancel mode
MessageBox.Show("The map has only one subsector. Please add more sectors, then try running this mode again.", "THY NODETH ARETH BROKH!", MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -105,7 +129,7 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
return false;
}
BinaryReader nodesreader = new BinaryReader(nodesstream);
nodes = new Node[numnodes];
for(int i = 0; i < nodes.Length; i++)
{