From 484b0817bd4a5efaeffa7d8d11c13dcbc0fa1966 Mon Sep 17 00:00:00 2001 From: biwa <6475593+biwa@users.noreply.github.com> Date: Thu, 3 Feb 2022 19:35:10 +0100 Subject: [PATCH] Snap selection to grid: fixed a problem that could cause a crash if geometry got removed by snapping it to the grid --- Source/Core/Editing/EditMode.cs | 4 ++++ Source/Core/General/MapManager.cs | 3 +++ .../BuilderModes/ClassicModes/LinedefsMode.cs | 10 ++++++++++ .../Plugins/BuilderModes/ClassicModes/SectorsMode.cs | 10 ++++++++++ .../BuilderModes/ClassicModes/VerticesMode.cs | 12 +++++++++++- 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Source/Core/Editing/EditMode.cs b/Source/Core/Editing/EditMode.cs index 6c8c3590..a2c4aa56 100755 --- a/Source/Core/Editing/EditMode.cs +++ b/Source/Core/Editing/EditMode.cs @@ -260,6 +260,10 @@ namespace CodeImp.DoomBuilder.Editing // Script events public virtual bool OnScriptRunBegin() { return true; } public virtual void OnScriptRunEnd() { } + + // This should be called by global actions (i.e. that are not part of an editing mode) when they changed map elements, + // so that the mode can react to it (for example by rebuilding a blockmap) + public virtual void OnMapElementsChanged() { } #endregion } diff --git a/Source/Core/General/MapManager.cs b/Source/Core/General/MapManager.cs index ace48966..20b06028 100755 --- a/Source/Core/General/MapManager.cs +++ b/Source/Core/General/MapManager.cs @@ -2643,6 +2643,9 @@ namespace CodeImp.DoomBuilder undoredo.WithdrawUndo(); } + // Let the current editing mode know that we changed something + General.Editing.Mode.OnMapElementsChanged(); + // Done General.Interface.RedrawDisplay(); Cursor.Current = Cursors.Default; diff --git a/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs index c7e2ee8b..cbd3261f 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs @@ -1217,6 +1217,16 @@ namespace CodeImp.DoomBuilder.BuilderModes return base.OnCopyBegin(); } + /// + /// If map elements have changed the blockmap needs to be recreated. + /// + public override void OnMapElementsChanged() + { + base.OnMapElementsChanged(); + + CreateBlockmap(); + } + //mxd private void RenderComment(Linedef l) { diff --git a/Source/Plugins/BuilderModes/ClassicModes/SectorsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/SectorsMode.cs index 7a3a6bcb..9bf15d9b 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/SectorsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/SectorsMode.cs @@ -1596,6 +1596,16 @@ namespace CodeImp.DoomBuilder.BuilderModes General.Interface.RedrawDisplay(); } + /// + /// If map elements have changed the blockmap needs to be recreated. + /// + public override void OnMapElementsChanged() + { + base.OnMapElementsChanged(); + + CreateBlockmap(); + } + //mxd public override void OnViewSelectionNumbersChanged(bool enabled) { diff --git a/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs b/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs index ab07bd24..ae68e7be 100755 --- a/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs @@ -759,7 +759,17 @@ namespace CodeImp.DoomBuilder.BuilderModes return base.OnCopyBegin(); } - + + /// + /// If map elements have changed the blockmap needs to be recreated. + /// + public override void OnMapElementsChanged() + { + base.OnMapElementsChanged(); + + CreateBlockmap(); + } + #endregion #region ================== Actions