Nodes Viewer Mode: fixed a problem where trying to engage the mode with an empty map could crash. Fixes #857

This commit is contained in:
biwa 2023-03-03 10:49:40 +01:00
parent bb7857d2bb
commit 6c53594ec8
2 changed files with 21 additions and 1 deletions

View file

@ -20,6 +20,11 @@
namespace CodeImp.DoomBuilder.Plugins.NodesViewer namespace CodeImp.DoomBuilder.Plugins.NodesViewer
{ {
internal class ToastMessages
{
public static readonly string NODESVIEWER = "nodesviewer";
}
public class BuilderPlug : Plug public class BuilderPlug : Plug
{ {
#region ================== Variables #region ================== Variables
@ -49,6 +54,9 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
// Keep a static reference // Keep a static reference
me = this; me = this;
// Register toasts
General.ToastManager.RegisterToast(ToastMessages.NODESVIEWER, "Nodes Viewer Mode", "Toasts related to Nodes Viewer Mode");
} }
// This is called when the plugin is terminated // This is called when the plugin is terminated

View file

@ -843,6 +843,13 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
Cursor.Current = Cursors.WaitCursor; Cursor.Current = Cursors.WaitCursor;
base.OnEngage(); base.OnEngage();
if(General.Map.Map.Vertices.Count == 0)
{
General.ToastManager.ShowToast(ToastMessages.NODESVIEWER, ToastType.ERROR, "Failed to engage Nodes Viewer Mode", "The map is empty.", "Failed to engage Nodes Viewer Mode: the map is empty");
General.Editing.CancelMode();
return;
}
//mxd //mxd
bool haveNodes = General.Map.LumpExists("NODES"); bool haveNodes = General.Map.LumpExists("NODES");
bool haveZnodes = General.Map.LumpExists("ZNODES"); bool haveZnodes = General.Map.LumpExists("ZNODES");
@ -853,7 +860,12 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer
if(General.Map.IsChanged || !(haveZnodes || (haveNodes || haveSectors || haveSegs || haveVerts))) if(General.Map.IsChanged || !(haveZnodes || (haveNodes || haveSectors || haveSegs || haveVerts)))
{ {
// We need to build the nodes! // We need to build the nodes!
if(!General.Map.RebuildNodes(General.Map.ConfigSettings.NodebuilderSave, true)) return; if (!General.Map.RebuildNodes(General.Map.ConfigSettings.NodebuilderSave, true))
{
General.ToastManager.ShowToast(ToastMessages.NODESVIEWER, ToastType.ERROR, "Failed to engage Nodes Viewer Mode", "Failed to rebuild the nodes.", "Failed to engage Nodes Viewer Mode: failed to rebuild the nodes");
General.Editing.CancelMode();
return;
}
//mxd. Update nodes availability //mxd. Update nodes availability
haveNodes = General.Map.LumpExists("NODES"); haveNodes = General.Map.LumpExists("NODES");